Convert one enum variant to another: impl From?

I have an enum with two variants, each a different way to represent the same thing. Let the code that uses it work in whichever space makes more sense for it.

My question: It seems there should be a rustic way convert between the two, what it is? I tried some "impl From" syntax, but the compiler and I both didn't seem to understand what I was talking about.

Thanks,

-kb

enum variants are standalone types; e.g. if you have an Option<String>, then the None variant and the Some(string) variant both have the type Option<String>.

You probably just want a method on the enum to do the conversion.

    // something like...
    fn into_var_b(self) -> Self { todo!() }
    fn as_var_b(&mut self) { todo!() }
1 Like

Thanks,

-kb

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.