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

Feature request: add Number::from_i64 and Number::from_u64 #1078

Open
olebedev opened this issue Oct 12, 2023 · 0 comments
Open

Feature request: add Number::from_i64 and Number::from_u64 #1078

olebedev opened this issue Oct 12, 2023 · 0 comments

Comments

@olebedev
Copy link

The use case

Currently it's not possible to construct a Value from neither i64 nor u64 but only from f64 which is a bit of a limitation.

For example, the code below will fail:

assert_eq!(
    json!(1),
    Value::Number(Number::from_f64(1)),
)

because of 1_u64 and 1_f64 mismatch. There is no other way to construct number either, only from f64.

Proposal

Add Number::from_i64 and Number::from_u64 to make it possible to construct Value::Number from these scalar types.

I would love to hear @dtolnay thoughts on the proposed addition :)

Thanks!
Oleg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant