I have a Vec whose size I have already checked and I would like to take the sole element out from it:
let widgets = vec![1];
if widgets.len() == 0 {
return Err(Box::from("No widgets"));
}
if widgets.len() > 1 {
return Err(Box::from("Too many widgets"));
}
let widget = widgets[0];
The index operation doesn't work because elements can't be moved out from a Vec.
What's an idiomatic (and clone-free) way to get that one element while consuming the Vec?