Created
July 26, 2023 15:49
-
-
Save sam0x17/41d1659281096ba6de75f2d2246dc371 to your computer and use it in GitHub Desktop.
Rust workaround for "the `?` operator can only be used in a closure that returns `Result` or `Option`" when trying to use `?` inside a closure inside a `.map`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let const_fns: Vec<TraitItemFn> = const_fns | |
.into_iter() | |
.map(|item| match item { | |
TraitItem::Fn(trait_item_fn) => Ok(*trait_item_fn), | |
_ => return Err(Error::new(item.span(), "expected `fn`")), | |
}) | |
.collect::<std::result::Result<_, Self::Error>>()?; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment