For example, if I have code like:
enum Foo {
Bar,
Baz,
Bat,
Quux
}
impl Foo {
from(input: &str) -> Foo {
Foo::input
}
}
This obviously will not work, because it is inputnot a Foo method. I can manually type:
from(input: &str) -> Foo {
match(input) {
"Bar" => Foo::Bar,
}
}
but I do not get automatic convenience.
It seems that Java has a function for finding strings in enums for this specific purpose.
Is it possible to get this without writing my own macro or importing from a box?
source
share