3 ms·
Oh, I missed that it's an Option. That means that it won't work today, but https://github.com/rust-lang/rust/pull/42526 https://github.com/rust-lang/rust/pull/
by steveklabnik 9y ago
Oh, I missed that it's an Option.
That means that it won't work today, but https://github.com/rust-lang/rust/pull/42526 https://github.com/rust-lang/rust/pull/42526 landed, and is in beta. This means on the next release of Rust, code like this will work:
fn try_result_some() -> Option<u8> {
let val = Some(1)?; // Ok also works
Some(val)
}
that is, using `?` on an Option in a function returning an Option.
That being said, similar code will not yet work:
fn try_result_some() -> Result<u8, Box<Error>> {
let val = Some(1)?;
Ok(val)
}
that is, using `?` on an Option in a function returning Result. This is because https://doc.rust-lang.org/nightly/std/option/struct.NoneError.html https://doc.rust-lang.org/nightly/std/option/struct.NoneErro... isn't stable yet.