deployer of worlds is a user on ceilidh.space. You can follow them or interact with them if you have an account anywhere in the fediverse. If you don't, you can sign up here.

did you know, if you have an iterator that emits Result<T, E>, you can collect it into a Result<Vec<T>, E>?

deployer of worlds @balrogboogie

Since an example fits in a toot:

extern crate rand;

fn resultize(i: usize) -> Result<usize, String> {
if rand::random() {
Ok(i)
} else {
Err("whoops!".into())
}
}

fn main() {
let iter = (0..10).map(|i| resultize(i));
let results = iter.collect::<Result<Vec<_>, _>>();
println!("{:?}", results);
}

· Web · 0 · 2