Is there a shorter and simpler way to achieve this:
let o: Option<i32> = ...;
let ve: Vec<i32> = match o {
None => vec![],
Some(n) => vec![n],
};
Is there a shorter and simpler way to achieve this:
let o: Option<i32> = ...;
let ve: Vec<i32> = match o {
None => vec![],
Some(n) => vec![n],
};
let o: Option<i32> = Some(2);
let ve: Vec<i32> = o.into_iter().collect();
Option implements IntoIterator, so you can make an iterator and collect it:
let ve: Vec<i32> = o.into_iter().collect();