Skip to content

Instantly share code, notes, and snippets.

@Thiez
Forked from rust-play/playground.rs
Created June 3, 2018 21:57
Show Gist options
  • Save Thiez/49cc68dbcaf681a3aee9d7ad083e1cd0 to your computer and use it in GitHub Desktop.
Save Thiez/49cc68dbcaf681a3aee9d7ad083e1cd0 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