struct A<T:Clone>{ data: Vec<T> } type AA = A<usize>; type BB<'a> = A<&'a str>; impl<T:Clone> From<T> for A<T> { fn from(c: T) -> Self { A { data: vec![c] } } } impl<T:Clone, const N:usize> From<[T;N]> for A<T> { fn from(c: [T;N]) -> Self { A{ data: c.to_vec() } } } impl<T:Clone> From<Vec<T>> for A<T> { fn from(c: Vec<T>) -> Self { A { data: c } } } fn sort_by_index(c: AA){} fn sort_by_name(c:BB){}
标签:AA,impl,type,Self,rust,data,fn From: https://www.cnblogs.com/pythonClub/p/16593016.html