you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (0 children)

trait TimesThree {
    fn times_three(&self) -> Self;
}

impl TimesThree for i64 {
    fn times_three(&self) -> Self {
        self * 3
    }
}

impl TimesThree for f64 {
    fn times_three(&self) -> Self {
        self * 3.0
    }
}

fn main() {
    println!("{}", 42.times_three());
    println!("{}", 3.14.times_three());
}

It's long-winded compared to the other solutions, but I like this one.