Похожие чаты

Something like that? trait Callback { fn callback(&self)

{
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

1 ответов

10 просмотров

mmh, actually I have to call Parent's some_operation() from within Child...or something like that

Похожие вопросы

Обсуждают сегодня

А еще в перле можно уже @arr1 + @arr2?
Sergei Zhmylove
53
я не магистр хаскеля, но разве не может лейзи тип конвертнуться в не-лейзи запросив вычисление содержимого прям при инициализации?
deadgnom32 λ madao
100
I arrived here after a Chico Crypto show highlighted the project & the Team - the fact that the Team had a long history of successfully working with household names gave me e...
Banter is Bullish
1
Привет всем. появился вопрос. Разрабатываю сайт, в данный момент он запущен. Хостинг beget. Добавляю на сайт яндекс метрику с помощью полей client-settings (взято отсюда http...
Andrew
2
Подскажите, где смотреть результат выполнения программы? Код: ;.686 ;Система команд процессора 686 ;.MODEL FLAT,stdcall ;Модель памяти плоская, станда...
Егор Анелькин
5
Где в Астане можно купить мясо для шашлыков?
Dancing Іңұқәһүғө
21
Lers say somehow tor got shut down What then?
Mark Keller
16
Добрый день подскажите пожалуйста может кто то сталкивался с ошибками Sentry 22.10.0 развернутым из helm чарт в Kubernetes? Изначально 3 дня назад очень стало много событий ух...
Tire4 Finist Devops
1
Gm, Oceaners🌟 We're going to #DappCon24 🇩🇪 between May 21-23 in Berlin to talk #blockchain future! If you're nearby, come by and say hello at our booth! Grab your tickets h...
KreigDK | Never DM first🌊
13
Ну чё, сегодня все в гавно?))
ᅠ🚀
20
Карта сайта