首页 > 其他分享 >rust type and impl

rust type and impl

时间:2022-08-16 21:25:03浏览次数:47  
标签:AA impl type Self rust data fn

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

相关文章