daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. trait DoerMaker {
  2.   type T: StuffDoer;
  3.   fn make_doer(&self) -> Self::T;
  4. }
  5.  
  6. trait StuffDoer {
  7.   fn do_stuff(&self) -> Option<()>;
  8. }
  9.  
  10. enum Foo {
  11.   A,
  12.   B,
  13.   C,
  14. }
  15.  
  16. struct Bar;
  17. impl DoerMaker for Bar {
  18.   type T=Box<StuffDoer>;
  19.  
  20.   fn make_doer(&self, f: Foo) -> Box<StuffDoer> {
  21.     match f {
  22.       Foo::A => Box::new(Baz{}),
  23.       Foo::B => Box::new(Bat{}),
  24.       Foo::C => Box::new(Bang{}),
  25.     }
  26.   }
  27. }
  28.  
  29. struct Baz;
  30. impl StuffDoer for Baz {
  31.   fn do_stuff(&self) -> Option<()> {
  32.     None
  33.   }
  34. }
  35.  
  36. struct Bat;
  37. impl StuffDoer for Bat {
  38.   fn do_stuff(&self) -> Option<()> {
  39.     None
  40.   }
  41. }
  42.  
  43. struct Bang;
  44. impl StuffDoer for Bang {
  45.   fn do_stuff(&self) -> Option<()> {
  46.     None
  47.   }
  48. }
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