Debian Codegraph @

README.md

raw symbols SCIP
1 # js_int
2
3 [![Latest Version](https://img.shields.io/crates/v/js_int.svg)][crates-io]
4 [![Docs](https://docs.rs/js_int/badge.svg)][docs-rs]
5
6 Crate `js_int` provides JavaScript-interoperable integer types.
7
8 JavaScript does not have native integers. Instead it represents all numeric
9 values with a single `Number` type which is represented as an
10 [IEEE 754 floating-point](https://en.wikipedia.org/wiki/IEEE_754) value.\*
11 Rust's `i64` and `u64` types can contain values outside the range of what can be
12 represented in a JavaScript `Number`.
13
14 This crate provides the types `Int` and `UInt` which wrap `i64` and `u64`,
15 respectively. These types add bounds checking to ensure the contained value is
16 within the range representable by a JavaScript `Number`. They provide useful
17 trait implementations to easily convert from Rust's primitive integer types.
18
19 <small>* In the upcoming ECMAScript 2020, JavaScript will probably gain support
20 for integers. There is a proposal for a [`BigInt`][mdn] type type that is not
21 far from becoming part of the JavaScript specification. It won't make this crate
22 obsolete in any way though, since there will still be lots of JS code using
23 `Number`, and code in other languages that assumes its use.
24 </small>
25
26 This crate requires rustc >= 1.35.
27
28 This crate is `no_std`-compatible with `default-features = false`. This will
29 disable the `std` feature, which at the time of writing will only omit the
30 implementations of `std::error::Error` for `ParseIntError` and
31 `TryFromIntError`.
32
33 (De-)Serialization via `serde` is supported via the `serde` feature, even
34 without the `std` feature.
35
36 Deserialization can be routed through `f64` instead of `u64` with the
37 `float_deserialize` feature. This will still not deserialize numbers with a
38 non-zero fractional component. Enabling the `lax_deserialize` feature will discard the
39 fractional part instead of declining to deserialize. Please be aware that
40 `serde_json` doesn't losslessly parse large floats with a fractional part by
41 default (even if the fractional part is `.0`). To fix that, enable its
42 `float_roundtrip` feature.
43
44 [travis]: https://travis-ci.org/jplatte/js_int
45 [crates-io]: https://crates.io/crates/js_int
46 [docs-rs]: https://docs.rs/js_int
47 [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt