Guest User

Untitled

a guest
Jan 22nd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  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 Baz {
  31. fn do_stuff(&self) -> Option<()> {
  32. None
  33. }
  34. }
  35.  
  36. struct Bat;
  37. impl Bat {
  38. fn do_stuff(&self) -> Option<()> {
  39. None
  40. }
  41. }
  42.  
  43. struct Bang;
  44. impl Bang {
  45. fn do_stuff(&self) -> Option<()> {
  46. None
  47. }
  48. }
Add Comment
Please, Sign In to add comment