1.
Vector is an array it’s length can be expended。
let mut a = Vec::new();
// init with one element at least
let mut a1= vec![1,2,33,44,55];
// the elements inner vec instace must be same type
enum One {
Ha,
String(String),
Number(u64)
}
let mut a1= vec![One::ha,One::String(String::from(“你好”))];
so how to traverse a1 it’s type is vec;
recommond for in;
Ha,
String(String),
Number(u64)
}
let mut a1= vec![One::ha,One::String(String::from(“你好”))];
for item in a1 {
}
print!(“{:#?}”,{a1});
in a1 the control is given to “for”,So after excuted for statement;
a1 was destroied;
you must use &a in order to borrow the reference;like bellow
Ha,
String(String),
Number(u64)
}
let mut a1= vec![One::ha,One::String(String::from(“你好”))];
for item in &a1 {
}
print!(“{:#?}”,{a1});
for statement
any Type that implement Iterator trait can be traverse by for;
if the value was traverse is not a borrow refrence; like this
for item in a{
}
a will try to mover the control to item;So a muse be a mutable;
for item in a{
}