Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait DoerMaker {
- type T: StuffDoer;
- fn make_doer(&self) -> Self::T;
- }
- trait StuffDoer {
- fn do_stuff(&self) -> Option<()>;
- }
- enum Foo {
- A,
- B,
- C,
- }
- struct Bar;
- impl DoerMaker for Bar {
- type T=Box<StuffDoer>;
- fn make_doer(&self, f: Foo) -> Box<StuffDoer> {
- match f {
- Foo::A => Box::new(Baz{}),
- Foo::B => Box::new(Bat{}),
- Foo::C => Box::new(Bang{}),
- }
- }
- }
- struct Baz;
- impl Baz {
- fn do_stuff(&self) -> Option<()> {
- None
- }
- }
- struct Bat;
- impl Bat {
- fn do_stuff(&self) -> Option<()> {
- None
- }
- }
- struct Bang;
- impl Bang {
- fn do_stuff(&self) -> Option<()> {
- None
- }
- }
Add Comment
Please, Sign In to add comment