For references into an array usually you'd just use a usize
rather than different integer types.
However, to do what you are after you can create a new trait, implement that trait for u16
, u32
and u64
and then restrict T to your new trait.
pub trait MyNewTrait {}
impl MyNewTrait for u16 {}
impl MyNewTrait for u32 {}
impl MyNewTrait for u64 {}
struct Foo<T: MyNewTrait> { ... }
You may then also add methods onto MyNewTrait
and the impl
s to encapsulate the logic specific to u16
, u32
and u64
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…