pub trait Observer{
type DataType;
fn new(action: fn(&mut Self::DataType))->Self;
fn update(&self, data:&mut Self::DataType);
}
pub trait Subject{
type ObserverType: Observer;
fn new()-> Self;
fn add_observer(&mut self,observer:Rc<Self::ObserverType>);
fn remove_observer(&mut self,observer:&Rc<Self::ObserverType>);
fn data(&mut self)-> &<<Self as Subject>::ObserverType as Observer>::DataType;
fn notification(&mut self);
}
pub struct SubjectMgr{
}
impl SubjectMgr {
fn new(){
let mut map = HashMap::new();
map.insert("PlayerList",PlayerListSubject::new());
map.insert("MonsterList",MonsterListSubject::new());
}
}
An attempt was made to use a hashmap with associate value as a member. But can't I have a hashmap value type?
The file structure is as follows: enter image description here