Created
April 13, 2014 11:23
-
-
Save bvssvni/10579832 to your computer and use it in GitHub Desktop.
Idea: Type match in Rust
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
/// 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