Skip to content

Instantly share code, notes, and snippets.

@nodakai
Created February 10, 2016 19:29
Show Gist options
  • Select an option

  • Save nodakai/dcdf94f2020cca956711 to your computer and use it in GitHub Desktop.

Select an option

Save nodakai/dcdf94f2020cca956711 to your computer and use it in GitHub Desktop.
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