Would it ever be possible for either of the following to be possible in the rust language because I feel that it could help with conciseness.
Example 1: returning from parent function in a “non-moveable” closure construct
fn foo (c_vec: Vec<C>) -> Result<Vec<D>, ErrorType> {
c_vec.into_iter()
.map('static |c| {
if let Ok(d) = D::try_from(c) {
d
} else {
return 'static ErrorType::new();
}
})
}
I know that the above example is a bit contrived but I have had instances in the past where something like this would have really help but instead I had to use other forms of iteration.
Example 2: using continue and break as “closures”
let list: Vec<Option<_>> = ...;
...
for item in list.iter() {
...
foo.bar(item.unwrap_or_else(continue));
}
I know that it is possible to write the second as an if statement.