SHARE
TWEET

Untitled

a guest Sep 21st, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top