Automatic parsing from str to my enum/struct?
Is it possible to tell Rust to convert str automatically into my type
No, that's not the sort of things Rust promotes / does / allows, even less so for faillible conversions. Rust intentionally has rather few implicit conversions, and even less so ones which run user-provided code.
If so, what's the point of
FromStr
?
That packages can use FromStr
as bounds in order to convert from strings to unknown types e.g. structopt can parse command-line parameters to arbitrarily complex structs.
For libraries, it also provides users with a relatively easy to discover interface e.g. the user can just check the list of traits, see that there's a FromStr
(or a TryFrom<&str>
these days) and know that they can use that to parse.