Crates.io | number_traits |
lib.rs | number_traits |
version | 0.2.4 |
source | src |
created_at | 2017-08-17 16:40:32.259716 |
updated_at | 2018-02-19 01:41:56.400528 |
description | number traits |
homepage | https://gitlab.com/nathanfaucett/rs-number_traits |
repository | https://gitlab.com/nathanfaucett/rs-number_traits.git |
max_upload_size | |
id | 27893 |
size | 80,764 |
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);
}