fn main() {
let a = Some(1);
let b = Some(2);
let c = Some(3);
//let c = None;
let abc: Option<(i32, i32, i32)> = (|| Some((a?, b?, c?)))();
println!("{:?}", abc);
}
I meant you can use the (|| Some((a?, b?, c?)))() syntax to convert an (Option<A>, Option<B>, Option<B>) into an Option<(a, b, c)>. Then you can do a single match for that option against Some(a, b, c), instead of (Some(a), Some(b), Some(c)).
Not sure which is more idiomatic though.
Ahh, your point isn't the (seemingly) nested match, but the double error reporting here?
I am wondering if there is a better way of writing this avoiding the big list of Some(),
and the yes the error messages are pretty much redundant, a list of length of 0 will output None for all the stat functions
Maybe a little strange, but you can use a function that returns Option and use ? within it.
#[test]
fn xxx() {
fn yyy() -> Option<()> {
let a = Some(1)?;
let b = Some(2)?;
let c = Some(3)?;
// let c: i32 = None?;
println!("{a} {b} {c}");
Some(())
}
assert_eq!(Some(()), yyy());
}