Skip to content

Instantly share code, notes, and snippets.

@bvssvni
Created April 13, 2014 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bvssvni/10579832 to your computer and use it in GitHub Desktop.
Save bvssvni/10579832 to your computer and use it in GitHub Desktop.
Idea: Type match in Rust
/// Returns true if T is int, otherwise false.
fn is_int<T: Num>(num: T) -> bool {
match <T> {
int => true,
_ => false,
}
}
/// Returns true if T impls Clone.
fn is_clone(val: T) -> bool {
match <T> {
<Clone> => true,
_ => false,
}
}
/// Returns true if both arguments impls Clone.
fn both_does_clone<T, U>(a: T, b: U) -> bool {
match <T, U> {
<Clone, Clone> => true,
_ = > false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment