Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait T {
- fn fn1(&self);
- }
- struct S {}
- impl T for S {
- fn fn1(&self) {
- dbg!("test");
- }
- }
- struct TWrapper {
- x: Box<dyn T>
- }
- impl TWrapper {
- fn fn2(&self) {
- self.x.fn1();
- }
- }
- fn f(t: &mut impl T) {
- let tw = TWrapper {
- x: Box::new(t)
- };
- tw.fn2();
- }
- fn main() {
- let mut s = S{};
- f(&mut s);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement