From 02d78c3e84c8f160b6f6487be0a368b5720bb67b Mon Sep 17 00:00:00 2001 From: Tostapunk Date: Mon, 18 Jul 2022 14:11:51 +0200 Subject: fix: Improve hint of lifetimes2 fixes #1071 --- info.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'info.toml') diff --git a/info.toml b/info.toml index 5b7b9b4..3ec15d7 100644 --- a/info.toml +++ b/info.toml @@ -795,7 +795,10 @@ name = "lifetimes2" path = "exercises/lifetimes/lifetimes2.rs" mode = "compile" hint = """ -What is the compiler checking? How could you change how long an owned variable lives?""" +Remember that the generic lifetime 'a will get the concrete lifetime that is equal to the smaller of the lifetimes of x and y. +You can take at leats two paths to achieve the desidered result while keeping the inner block: +1. move string2 declaration to make it live as long as string1 (how is result declared?) +2. move println! into the inner block""" [[exercises]] name = "lifetimes3" -- cgit v1.2.3 From e1d6abb4c919386fd5c728a30db73d160c6fe373 Mon Sep 17 00:00:00 2001 From: Mattia Schiavon Date: Mon, 18 Jul 2022 14:44:16 +0200 Subject: Apply suggestions from code review Co-authored-by: liv --- info.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'info.toml') diff --git a/info.toml b/info.toml index 3ec15d7..0be3e91 100644 --- a/info.toml +++ b/info.toml @@ -796,9 +796,9 @@ path = "exercises/lifetimes/lifetimes2.rs" mode = "compile" hint = """ Remember that the generic lifetime 'a will get the concrete lifetime that is equal to the smaller of the lifetimes of x and y. -You can take at leats two paths to achieve the desidered result while keeping the inner block: -1. move string2 declaration to make it live as long as string1 (how is result declared?) -2. move println! into the inner block""" +You can take at least two paths to achieve the desired result while keeping the inner block: +1. Move the string2 declaration to make it live as long as string1 (how is result declared?) +2. Move println! into the inner block""" [[exercises]] name = "lifetimes3" -- cgit v1.2.3 From 8a4dca5fa63913d42eddd443485f5a7c9d9f5319 Mon Sep 17 00:00:00 2001 From: Eric Jolibois Date: Tue, 19 Jul 2022 11:45:34 +0200 Subject: remove small typo in hint of threads3 --- info.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'info.toml') diff --git a/info.toml b/info.toml index 0be3e91..f90d10a 100644 --- a/info.toml +++ b/info.toml @@ -988,7 +988,7 @@ An alternate way to handle concurrency between threads is to use a mpsc (multiple producer, single consumer) channel to communicate. With both a sending end and a receiving end, it's possible to send values in one thread and receieve them in another. -Multiple producers are possibile by using clone() to create a duplicate +Multiple producers are possible by using clone() to create a duplicate of the original sending end. See https://doc.rust-lang.org/book/ch16-02-message-passing.html for more info. """ -- cgit v1.2.3 From f9413b8ae1c9fe8bd9ebed01f27450e8b98f233e Mon Sep 17 00:00:00 2001 From: Greg Leonard Date: Tue, 19 Jul 2022 20:05:04 +0100 Subject: fix(traits5): fix "paramter" spelling --- info.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'info.toml') diff --git a/info.toml b/info.toml index f90d10a..1403111 100644 --- a/info.toml +++ b/info.toml @@ -732,7 +732,7 @@ name = "traits5" path = "exercises/traits/traits5.rs" mode = "compile" hint = """ -To ensure a paramter implements multiple traits use the '+ syntax'. Try replacing the +To ensure a parameter implements multiple traits use the '+ syntax'. Try replacing the '??' with 'impl <> + <>'. See the documentation at: https://doc.rust-lang.org/book/ch10-02-traits.html#specifying-multiple-trait-bounds-with-the--syntax -- cgit v1.2.3 From f88c7d1e8c89d26f5180082d68d4b79e4ec47b48 Mon Sep 17 00:00:00 2001 From: Jeremy Goh <30731072+thatlittleboy@users.noreply.github.com> Date: Sun, 24 Jul 2022 00:36:27 +0800 Subject: fix: reference to variables4 --- info.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'info.toml') diff --git a/info.toml b/info.toml index 1403111..7bb753e 100644 --- a/info.toml +++ b/info.toml @@ -63,7 +63,7 @@ name = "variables5" path = "exercises/variables/variables5.rs" mode = "compile" hint = """ -In variables3 we already learned how to make an immutable variable mutable +In variables4 we already learned how to make an immutable variable mutable using a special keyword. Unfortunately this doesn't help us much in this exercise because we want to assign a different typed value to an existing variable. Sometimes you may also like to reuse existing variable names because you are just converting -- cgit v1.2.3 From 301bc52857554e047eabf32fec323f7a10e2b853 Mon Sep 17 00:00:00 2001 From: Jeremy Goh <30731072+thatlittleboy@users.noreply.github.com> Date: Sun, 24 Jul 2022 00:37:40 +0800 Subject: fix: lineno typo --- info.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'info.toml') diff --git a/info.toml b/info.toml index 7bb753e..f07b926 100644 --- a/info.toml +++ b/info.toml @@ -123,8 +123,8 @@ name = "functions4" path = "exercises/functions/functions4.rs" mode = "compile" hint = """ -The error message points to line 14 and says it expects a type after the -`->`. This is where the function's return type should be-- take a look at +The error message points to line 17 and says it expects a type after the +`->`. This is where the function's return type should be -- take a look at the `is_even` function for an example! Also: Did you figure out that, technically, u32 would be the more fitting type -- cgit v1.2.3 From 72e21a2a6c2654cb1d2e292291e2e40914957776 Mon Sep 17 00:00:00 2001 From: Denton24646 Date: Sat, 23 Jul 2022 17:57:03 -0400 Subject: feat: add cow1.rs exercise --- exercises/standard_library_types/cow1.rs | 48 ++++++++++++++++++++++++++++++++ info.toml | 11 ++++++++ 2 files changed, 59 insertions(+) create mode 100644 exercises/standard_library_types/cow1.rs (limited to 'info.toml') diff --git a/exercises/standard_library_types/cow1.rs b/exercises/standard_library_types/cow1.rs new file mode 100644 index 0000000..5fba251 --- /dev/null +++ b/exercises/standard_library_types/cow1.rs @@ -0,0 +1,48 @@ +// cow1.rs + +// This exercise explores the Cow, or Clone-On-Write type. +// Cow is a clone-on-write smart pointer. +// It can enclose and provide immutable access to borrowed data, and clone the data lazily when mutation or ownership is required. +// The type is designed to work with general borrowed data via the Borrow trait. + +// I AM NOT DONE + +use std::borrow::Cow; + +fn abs_all<'a, 'b>(input: &'a mut Cow<'b, [i32]>) -> &'a mut Cow<'b, [i32]> { + for i in 0..input.len() { + let v = input[i]; + if v < 0 { + // Clones into a vector if not already owned. + input.to_mut()[i] = -v; + } + } + input +} + +fn main() { + // No clone occurs because `input` doesn't need to be mutated. + let slice = [0, 1, 2]; + let mut input = Cow::from(&slice[..]); + match abs_all(&mut input) { + Cow::Borrowed(_) => println!("I borrowed the slice!"), + _ => panic!("expected borrowed value"), + } + + // Clone occurs because `input` needs to be mutated. + let slice = [-1, 0, 1]; + let mut input = Cow::from(&slice[..]); + match abs_all(&mut input) { + Cow::Owned(_) => println!("I modified the slice and now own it!"), + _ => panic!("expected owned value"), + } + + // No clone occurs because `input` is already owned. + let slice = vec![-1, 0, 1]; + let mut input = Cow::from(slice); + match abs_all(&mut input) { + // TODO + Cow::Borrowed(_) => println!("I own this slice!"), + _ => panic!("expected borrowed value"), + } +} diff --git a/info.toml b/info.toml index 1403111..230fc72 100644 --- a/info.toml +++ b/info.toml @@ -932,6 +932,17 @@ is too much of a struggle, consider reading through all of Chapter 16 in the boo https://doc.rust-lang.org/stable/book/ch16-00-concurrency.html """ +[[exercises]] +name = "cow1" +path = "exercises/standard_library_types/cow1.rs" +mode = "compile" +hint = """ +Since the vector is already owned, the `Cow` type doesn't need to clone it. + +Checkout https://doc.rust-lang.org/std/borrow/enum.Cow.html for documentation +on the `Cow` type. +""" + # THREADS [[exercises]] -- cgit v1.2.3 From a3a5fbeddf7ad891514a7cf4d51a582efdedb0f1 Mon Sep 17 00:00:00 2001 From: Claire Wang Date: Mon, 25 Jul 2022 17:54:09 -0700 Subject: fix: remove extra " typo in info.toml --- info.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'info.toml') diff --git a/info.toml b/info.toml index f07b926..dc1485d 100644 --- a/info.toml +++ b/info.toml @@ -746,7 +746,7 @@ path = "exercises/quiz3.rs" mode = "test" hint = """ To find the best solution to this challenge you're going to need to think back to your -knowledge of traits, specifically Trait Bound Syntax - you may also need this: "use std::fmt::Display;"""" +knowledge of traits, specifically Trait Bound Syntax - you may also need this: `use std::fmt::Display;`.""" # TESTS -- cgit v1.2.3