Generic struct vec

Hello,

I would like to generalize this struct, but I block on this error

pub struct lst_position { 
    pub list : Vec<(ProcessUniqueId,Position)>,
}

impl lst_position {
    
    pub fn new () -> lst_position {
        let mut list = Vec::new();
        lst_position::init_list(&mut list);
        lst_position {list : list}
    }
    // -- To-Do -- merged with new
    fn init_list(p_list: &mut Vec<(ProcessUniqueId,Position)>){
        
        let id1 = ProcessUniqueId::new();
        let pos : Position = Position { x : 0.0,  y  : 0.0 };
        p_list.push((id1, pos));
    }

    pub fn add(&mut self, pos : Position) -> ProcessUniqueId {
        
        let id1 = ProcessUniqueId::new();       
        self.list.push((id1,pos)); 
        id1
    } 
}

i began by

pub struct List<T> {
    pub lst : Vec<ProcessUniqueId,T>,
}

i have this error

pub struct List<T>
wrong number of type arguments: expected 1, found 2

Thank for your help

In the original struct, you were using a Vec of tuples. Use it here too:

pub struct List<T> {
    pub lst : Vec<(ProcessUniqueId, T)>,
}

:lol, how does it feel idio, thanks. ^^

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.