from-str

TIL about the FromStr trait in Rust that is implicitly used through str’s parse method.

We could have a struct called Period that parses a string like: “10 days” into Period { value: 10, timeframe: "days" }. The way to use it would be:

let period = "10 days".parse::<Period>();