How to achieve different `impl' for each enum members?

enum Foo{

trait common {
  fn setup();

//both of these impl gives compilation error
impl common for Foo::Bar_1 {


impl common for Foo::Bar_2 {


I have above code where i want to have different impl for each Bar_* . Is it even possible ? how i can achieve these behavior?

No. That is what match is for. In the previous post, RedDocMD has shown you how you can match on an enum in order to check which of its variants is currently active.

1 Like

When you are using enums as a replacement for inheritance, you typically do not need a trait.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.