For example, if I have code like:
enum Foo {
Bar,
Baz,
Bat,
Quux
}
impl Foo {
from(input: &str) -> Foo {
Foo::input
}
}
This will obviously fail because input
is not a method of Foo. I can manually type:
from(input: &str) -> Foo {
match(input) {
"Bar" => Foo::Bar,
// and so on...
}
}
but I'm not getting the automatic convenience.
It looks like Java has a string lookup function on enums for this specific purpose.
Is it possible to get this without writing my own macro or importing one from a crate?