~jplatte/js_int

JavaScript-interoperable integer types for Rust
3733e6bb — Jonas Platte 5 days ago
Bump version
e81a27e7 — Jonas Platte 5 days ago
Rewrite Deserialize implementations
6cf9c7e1 — Jonas Platte 24 days ago
Bump version

clone

read-only
https://git.sr.ht/~jplatte/js_int
read/write
git@git.sr.ht:~jplatte/js_int

You can also use your local clone with git send-email.

js_int

Crate js_int provides JavaScript-interoperable integer types.

JavaScript does not have native integers. Instead it represents all numeric values with a single Number type which is represented as an IEEE 754 floating-point value.* Rust's i64 and u64 types can contain values outside the range of what can be represented in a JavaScript Number.

This crate provides the types Int and UInt which wrap i64 and u64, respectively. These types add bounds checking to ensure the contained value is within the range representable by a JavaScript Number. They provide useful trait implementations to easily convert from Rust's primitive integer types.

* In the upcoming ECMAScript 2020, JavaScript will probably gain support for integers. There is a proposal for a BigInt type type that is not far from becoming part of the JavaScript specification. It won't make this crate obsolete in any way though, since there will still be lots of JS code using Number, and code in other languages that assumes its use.

This crate requires rustc >= 1.34.2.

This crate is no_std-compatible with default-features = false. This will disable the std feature, which at the time of writing will only omit the implementations of std::error::Error for ParseIntError and TryFromIntError.

(De-)Serialization via serde is supported via the serde feature, even without the std feature.

Deserialization of Int and UInt form values and path parameters for users of the Rocket web framework version 0.4 are supported via the rocket_04 feature.