Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait Ext {
- fn test(&self);
- }
- // A
- struct A(String);
- impl A {
- fn new(v: impl AsRef<str>) -> A { A(v.as_ref().to_owned()) }
- }
- impl Ext for A {
- fn test(&self) {
- println!("A [{}]: Hello, world!", self.0);
- }
- }
- // B with A inside
- struct B<T>(String, T);
- impl<T: Ext> B<T> {
- fn new(v: impl AsRef<str>, inner: T) -> B<T> { B(v.as_ref().to_owned(), inner) }
- }
- impl<T: Ext> Ext for B<T> {
- fn test(&self) {
- self.1.test();
- println!("B [{}]: Hello, world!", self.0);
- }
- }
- // APP
- struct App {
- inner: Box<dyn Ext>,
- }
- impl App {
- fn test(&self) { self.inner.test() }
- }
- fn main() {
- let app = App {
- inner: Box::new(A::new("test-1")),
- };
- // TODO:...
- app.test();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement