So say I have this struct:
struct ParamStruct{
pub key: i32,
pub value: String,
}
And I also have a vector vec_params
containing several values of the struct.
Now, if I want a vector containing only the key
variable in that Struct, I can do:
let mut vec_key:Vec<i32>=Vec::new();
for i in 0..vec_params.len(){
vec_key.push(vec_params[i].key)
}
Which is fine and all, and it's very trivial, but are there any quicker or methodological way? 4 lines of code is not much but I just want to know if there is any quick syntax to do it.