-
-
Save Thiez/49cc68dbcaf681a3aee9d7ad083e1cd0 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains 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
fn main() {} | |
fn unwrap_array<T>(input: [Option<T>; 2]) -> Option<[T; 2]> { | |
// Note: `{ }` is required here. | |
match {input} { | |
[Some(a), Some(b)] => Some([a, b]), | |
_ => None, | |
} | |
} | |
fn unwrap_tuple<T>(input: (Option<T>, Option<T>)) -> Option<[T; 2]> { | |
// But optional here. | |
match input { | |
(Some(a), Some(b)) => Some([a, b]), | |
_ => None, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment