Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decimal: replace homebuilt try_from with FromStr impl #1037

Open
coriolinus opened this issue Nov 21, 2020 · 0 comments
Open

decimal: replace homebuilt try_from with FromStr impl #1037

coriolinus opened this issue Nov 21, 2020 · 0 comments

Comments

@coriolinus
Copy link
Member

pub fn try_from(mut input: &str) -> Option<Decimal> {

It's more idiomatic and expressive to impl FromStr for Decimal instead of using a custom parse method. This is very slightly harder for the students, but it makes usage much nicer:

- let decimal = Decimal.try_from("123.45")?;
+ let decimal: Decimal = "123.45".parse()?;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant