Created
February 10, 2016 19:29
-
-
Save nodakai/dcdf94f2020cca956711 to your computer and use it in GitHub Desktop.
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
| trait Into_<T> { | |
| fn into(self) -> T; | |
| } | |
| impl Into_<i32> for i8 { | |
| fn into(self) -> i32 { self as i32 } | |
| } | |
| impl Into_<i32> for bool { | |
| fn into(self) -> i32 { self as i32 } | |
| } | |
| fn abs_i32<T>(a: T) -> i32 | |
| where T: Into_<i32> | |
| { | |
| a.into().abs() | |
| } | |
| fn main() { | |
| println!("{} {}", abs_i32(true), abs_i32(false)); | |
| println!("{}", abs_i32(-100i8)); | |
| // 1i32 as bool; | |
| true as i32; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment