Rust 泛型结构体

fn main(){
   
   let mut q1 : Queue<u8> = Queue::new();
   q1.push(3);
   q1.push(4);
   println!("{:#?}",q1);
   println!("{}",q1.is_empty());
}
#[derive(Debug,Clone)]
pub struct Queue<T>{
    older:Vec<T>,
    younger: Vec<T>
}
impl <T> Queue<T> {
    pub fn new() ->  Self {
        Queue{older:Vec::new(), younger: Vec::new()}
    }
    pub fn push(&mut self,t:T){
        self.younger.push(t);
    }
    pub fn is_empty(&self)-> bool{
        self.younger.is_empty() && self.older.is_empty()
    } 

}

你可能感兴趣的:(笔记,Rust)