Can I conditionally provide an initialization for a vector or no initialization at all?
fn main() {
let b = true;
let a = vec![
if b {"b"} //error[E0317]: `if` may be missing an `else` clause
];
println!("{:?}", a);
}
The vec! macro doesn't support this, but you can use normal functions on Vec:
fn main() {
let b = true;
let mut a = Vec::new();
if b {
a.push("b");
}
println!("{:?}", a);
}
if b { vec!["b"] } else { vec![] }