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

impl From<Number> for Value is missing #736

Closed
imp opened this issue Dec 28, 2020 · 0 comments · Fixed by #737
Closed

impl From<Number> for Value is missing #736

imp opened this issue Dec 28, 2020 · 0 comments · Fixed by #737

Comments

@imp
Copy link
Contributor

imp commented Dec 28, 2020

This could be useful at times. The concrete use case I have is a string that needs to be converted to Value. The string could be either numerical in which case it should be Value::Number or just a text, in which case it will be Value::String.
So I am using next code:

// text here is &str
if let Ok(number) = text.parse::<Number>() {
    Value::Number(number)
} else {
    Value::from(text)
}

Writing Value::from(number) feels cleaner

imp added a commit to imp/json that referenced this issue Dec 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant