{
println!("default callback implementation")
}
}
and Parent and Child structs
struct Parent {}
impl Parent {
pub fn some_operation(&self) {
self.callback();
}
}
impl Callback for Parent {}
struct Child {
name: String,
}
impl Child {
pub fn some_operation(&self) {
self.callback();
}
}
impl Callback for Child {
fn callback(&self) {
println!("hello from {}", self.name)
}
}
and usage
let parent = Parent {};
let child = Child {
name: "Child".to_string(),
};
parent.some_operation();
child.some_operation();
this outputs
default callback implementation
hello from Child
mmh, actually I have to call Parent's some_operation() from within Child...or something like that
Обсуждают сегодня