Created
June 3, 2018 21:57
-
-
Save rust-play/c2b0bd0f440df3ef1af11c48d2a9cb23 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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
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