Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. trait T {
  2. fn fn1(&self);
  3. }
  4.  
  5. struct S {}
  6.  
  7. impl T for S {
  8. fn fn1(&self) {
  9. dbg!("test");
  10. }
  11. }
  12.  
  13. struct TWrapper {
  14. x: Box<dyn T>
  15. }
  16.  
  17. impl TWrapper {
  18. fn fn2(&self) {
  19. self.x.fn1();
  20. }
  21. }
  22.  
  23. fn f(t: &mut impl T) {
  24. let tw = TWrapper {
  25. x: Box::new(t)
  26. };
  27. tw.fn2();
  28. }
  29.  
  30. fn main() {
  31. let mut s = S{};
  32. f(&mut s);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement