mirror of
https://github.com/notohh/rustlings.git
synced 2024-10-30 08:49:12 -04:00
Improve the comments in cow1
This commit is contained in:
parent
a5f221aa39
commit
9d7b973a62
2 changed files with 12 additions and 10 deletions
|
@ -45,8 +45,9 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn owned_no_mutation() {
|
fn owned_no_mutation() {
|
||||||
// We can also pass `vec` without `&` so `Cow` owns it directly. In this
|
// We can also pass `vec` without `&` so `Cow` owns it directly. In this
|
||||||
// case, no mutation occurs and thus also no clone. But the result is
|
// case, no mutation occurs (all numbers are already absolute) and thus
|
||||||
// still owned because it was never borrowed or mutated.
|
// also no clone. But the result is still owned because it was never
|
||||||
|
// borrowed or mutated.
|
||||||
let vec = vec![0, 1, 2];
|
let vec = vec![0, 1, 2];
|
||||||
let mut input = Cow::from(vec);
|
let mut input = Cow::from(vec);
|
||||||
abs_all(&mut input);
|
abs_all(&mut input);
|
||||||
|
@ -56,9 +57,9 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn owned_mutation() {
|
fn owned_mutation() {
|
||||||
// Of course this is also the case if a mutation does occur. In this
|
// Of course this is also the case if a mutation does occur (not all
|
||||||
// case, the call to `to_mut()` in the `abs_all` function returns a
|
// numbers are absolute). In this case, the call to `to_mut()` in the
|
||||||
// reference to the same data as before.
|
// `abs_all` function returns a reference to the same data as before.
|
||||||
let vec = vec![-1, 0, 1];
|
let vec = vec![-1, 0, 1];
|
||||||
let mut input = Cow::from(vec);
|
let mut input = Cow::from(vec);
|
||||||
abs_all(&mut input);
|
abs_all(&mut input);
|
||||||
|
|
|
@ -45,8 +45,9 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn owned_no_mutation() {
|
fn owned_no_mutation() {
|
||||||
// We can also pass `vec` without `&` so `Cow` owns it directly. In this
|
// We can also pass `vec` without `&` so `Cow` owns it directly. In this
|
||||||
// case, no mutation occurs and thus also no clone. But the result is
|
// case, no mutation occurs (all numbers are already absolute) and thus
|
||||||
// still owned because it was never borrowed or mutated.
|
// also no clone. But the result is still owned because it was never
|
||||||
|
// borrowed or mutated.
|
||||||
let vec = vec![0, 1, 2];
|
let vec = vec![0, 1, 2];
|
||||||
let mut input = Cow::from(vec);
|
let mut input = Cow::from(vec);
|
||||||
abs_all(&mut input);
|
abs_all(&mut input);
|
||||||
|
@ -56,9 +57,9 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn owned_mutation() {
|
fn owned_mutation() {
|
||||||
// Of course this is also the case if a mutation does occur. In this
|
// Of course this is also the case if a mutation does occur (not all
|
||||||
// case, the call to `to_mut()` in the `abs_all` function returns a
|
// numbers are absolute). In this case, the call to `to_mut()` in the
|
||||||
// reference to the same data as before.
|
// `abs_all` function returns a reference to the same data as before.
|
||||||
let vec = vec![-1, 0, 1];
|
let vec = vec![-1, 0, 1];
|
||||||
let mut input = Cow::from(vec);
|
let mut input = Cow::from(vec);
|
||||||
abs_all(&mut input);
|
abs_all(&mut input);
|
||||||
|
|
Loading…
Reference in a new issue