number_traits

Crates.ionumber_traits
lib.rsnumber_traits
version0.2.4
sourcesrc
created_at2017-08-17 16:40:32.259716
updated_at2018-02-19 01:41:56.400528
descriptionnumber traits
homepagehttps://gitlab.com/nathanfaucett/rs-number_traits
repositoryhttps://gitlab.com/nathanfaucett/rs-number_traits.git
max_upload_size
id27893
size80,764
Nathan Faucett (nathanfaucett)

documentation

README

rs-number_traits

number traits

extern crate number_traits;


use number_traits::{Num, Sqrt};


fn add<T>(a: T, b: T) -> T
    where T: Num,
{
    a + b
}

fn sqrt<T>(x: T) -> <T as Sqrt>::Output
    where T: Sqrt,
{
    x.sqrt()
}


fn main() {
    assert_eq!(add(2, 2), 4);
    assert_eq!(add(2.0, 2.0), 4);
    assert_eq!(sqrt(4), 2);
    assert_eq!(sqrt(4.0), 2);
}
Commit count: 19

cargo fmt