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

Add TryFrom<JsValue> for [iu](64|128) #3058

Merged
merged 3 commits into from Sep 4, 2022

Conversation

RReverser
Copy link
Member

@RReverser RReverser commented Sep 2, 2022

Adds a way to convert JsValue or a BigInt to i64/u64/i128/u128 with type and range checks, returning the original JsValue otherwise.

This could be optimised a little bit further via more intrinsics, but it's good enough for the initial implementation, so leaving any optimisations for the future.

Fixes #2350.

@RReverser RReverser marked this pull request as ready for review September 2, 2022 14:32
Adds a way to convert `JsValue` or a `BigInt` to `i64`/`u64`/`i128`/`u128` with type and range checks, returning the original `JsValue` otherwise.

This could be optimised a little bit further via more intrinsics, but it's good enough for the initial implementation, so leaving any optimisations for the future.

Fixes rustwasm#2350.
@RReverser
Copy link
Member Author

Rebased.

@Liamolucko Liamolucko merged commit cb94b43 into rustwasm:main Sep 4, 2022
@RReverser RReverser deleted the try-from-bigint branch September 4, 2022 09:51
@RReverser
Copy link
Member Author

Any chance for a release sometime soon? I want to release new version of serde-wasm-bindgen that would depend on this PR + #3049.

@Liamolucko
Copy link
Collaborator

v0.2.83 already includes those changes. (It doesn't seem to have been added as a proper GitHub release.)

@RReverser
Copy link
Member Author

(It doesn't seem to have been added as a proper GitHub release.)

Ahh yeah that's what I was tracking / checking regularly, so missed a release.

@cdecompilador
Copy link

Why not also adding [iu](8|16|32) to the pack?, I just needed for my application those implementations

@RReverser
Copy link
Member Author

Why not also adding [iu](8|16|32) to the pack?, I just needed for my application those implementations

They are more complicated / would make a bit less sense because they're all represented by a generic number (Rust's f64) on the JS side, while bigints are all exact integers with separate type.

You can always convert from f64 to specific integer type yourself though.

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

Successfully merging this pull request may close these issues.

Better support for u64 through JSValue::as_u64() and u64::into() -> JsValue
3 participants