Skip to content

Instantly share code, notes, and snippets.

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