[][src]Function tao_of_rust::ch03::traits::trait_bound

pub fn trait_bound()

trait bound 泛型约束

Base usage:

use std::ops::Add;
fn sum<T: Add<T, Output=T>>(a: T, b: T) -> T{
    a + b
}

assert_eq!(sum(1u32, 2u32), 3);
assert_eq!(sum(1u64, 2u64), 3);Run