diff options
| author | tajo48 <55502906+tajo48@users.noreply.github.com> | 2023-06-15 00:46:45 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-15 00:46:45 +0200 |
| commit | e1704a2f1bd2e1c92e0741d656228fe6ccf36a35 (patch) | |
| tree | 6bbd1dd1ea127dd652e0fe64093c10a78734fdf5 /exercises/smart_pointers/cow1.rs | |
| parent | 1e02f194fdd1cb1ca99cf1d93d11455db8b1bce6 (diff) | |
| parent | 0282da6881c0708b5aaf6a01e731b88b61201f71 (diff) | |
Merge branch 'main' into main
Diffstat (limited to 'exercises/smart_pointers/cow1.rs')
| -rw-r--r-- | exercises/smart_pointers/cow1.rs | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/exercises/smart_pointers/cow1.rs b/exercises/smart_pointers/cow1.rs index bc5b28e..7ca9168 100644 --- a/exercises/smart_pointers/cow1.rs +++ b/exercises/smart_pointers/cow1.rs @@ -1,12 +1,16 @@ // 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. +// +// 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. // // This exercise is meant to show you what to expect when passing data to Cow. -// Fix the unit tests by checking for Cow::Owned(_) and Cow::Borrowed(_) at the TODO markers. +// Fix the unit tests by checking for Cow::Owned(_) and Cow::Borrowed(_) at the +// TODO markers. +// +// Execute `rustlings hint cow1` or use the `hint` watch subcommand for a hint. // I AM NOT DONE @@ -50,10 +54,9 @@ mod tests { #[test] fn owned_no_mutation() -> Result<(), &'static str> { - // We can also pass `slice` without `&` so Cow owns it directly. - // In this case no mutation occurs and thus also no clone, - // but the result is still owned because it was never borrowed - // or mutated. + // We can also pass `slice` without `&` so Cow owns it directly. In this + // case no mutation occurs and thus also no clone, but the result is + // still owned because it was never borrowed or mutated. let slice = vec![0, 1, 2]; let mut input = Cow::from(slice); match abs_all(&mut input) { @@ -63,9 +66,9 @@ mod tests { #[test] fn owned_mutation() -> Result<(), &'static str> { - // Of course this is also the case if a mutation does occur. - // In this case the call to `to_mut()` returns a reference to - // the same data as before. + // Of course this is also the case if a mutation does occur. In this + // case the call to `to_mut()` returns a reference to the same data as + // before. let slice = vec![-1, 0, 1]; let mut input = Cow::from(slice); match abs_all(&mut input) { |
