added(): save

This commit is contained in:
Tomasz Waszczyk 2022-07-07 21:54:41 +02:00
parent fa90ef60ee
commit e95d515ffd
No known key found for this signature in database
GPG Key ID: D2B26226E770BBAA
5 changed files with 23 additions and 15 deletions

View File

@ -2,14 +2,14 @@
// Make me compile without changing line 13 or moving line 10!
// Execute `rustlings hint move_semantics2` for hints :)
// I AM NOT DONE
// TOTHINK
fn main() {
let vec0 = Vec::new();
pub fn main() {
let vec0 : Vec<i32> = Vec::new();
let vec_ = Vec::new();
let mut vec1 = fill_vec(vec0);
let mut vec1 = fill_vec(vec_);
let vec0 = vec1.clone();
// Do not change the following line!
println!("{} has length {} content `{:?}`", "vec0", vec0.len(), vec0);

View File

@ -17,7 +17,7 @@ fn main() {
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
}
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
fn fill_vec(mut vec: Vec<i32>) -> Vec<i32> {
vec.push(22);
vec.push(44);
vec.push(66);

View File

@ -4,13 +4,13 @@
// freshly created vector from fill_vec to its caller.
// Execute `rustlings hint move_semantics4` for hints!
// I AM NOT DONE
fn main() {
let vec0 = Vec::new();
let mut vec1 = fill_vec(vec0);
// let vec0 = Vec::new();
// let mut vec1 = fill_vec(vec0);
let mut vec1 = fill_vec();
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
vec1.push(88);
@ -20,7 +20,8 @@ fn main() {
// `fill_vec()` no longer takes `vec: Vec<i32>` as argument
fn fill_vec() -> Vec<i32> {
let mut vec = vec;
// let mut vec = vec;
let mut vec = Vec::new();
vec.push(22);
vec.push(44);

View File

@ -3,13 +3,17 @@
// adding, changing or removing any of them.
// Execute `rustlings hint move_semantics5` for hints :)
// I AM NOT DONE
// TOTHINK
fn main() {
let mut x = 100;
let y = &mut x;
let z = &mut x;
*y += 100;
*z += 1000;
let y = &mut x; //cannot borrow `x` as mutable more than once at a time
*y += 100;
assert_eq!(x, 1200);
}

View File

@ -15,7 +15,10 @@ trait AppendBar {
}
impl AppendBar for String {
//Add your code here
fn append_bar(self) -> Vec<String> {
self.push("Bar".to_string());
self
}
}
fn main() {