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.
deployer of worlds @balrogboogie

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

· Web · 0 · 2

@balrogboogie ah that's pretty interesting. I just injected an Err into the resultize() function and it yielded the error perfectly. Very cool!

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);
}