#[non_exhaustive]pub enum Numbers {
IntegerText,
WholeValues,
}Expand description
How typed reads (FromJson) of integers treat a
number written as a fraction or with an exponent.
JSON has one number type, and writers differ on how they spell a whole
number: some write 100, some 100.0 or 1e2. The default reads an
integer type only from integer text, as Number::as_i64
does, so a value that was meant as a float is never silently taken as an
integer. WholeValues also accepts any spelling of a whole number, read
exactly (Number::whole_value); a
fractional value is still refused.
The enum is #[non_exhaustive].
§Examples
use jsonx_lib::{Numbers, Parser};
assert!(Parser::new().decode::<u32>("1e2").is_err());
let lenient = Parser::new().numbers(Numbers::WholeValues);
assert_eq!(lenient.decode::<u32>("1e2")?, 100);
assert_eq!(lenient.decode::<u32>("7.0")?, 7);
assert!(lenient.decode::<u32>("7.5").is_err());Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
IntegerText
Integers from integer text only (100); 1e2 and 100.0 are
refused for an integer type. The default.
WholeValues
Integers from any spelling of a whole number (100, 1e2,
100.0), within i128’s range for exponent or fraction forms.
Trait Implementations§
impl Copy for Numbers
impl Eq for Numbers
impl StructuralPartialEq for Numbers
Auto Trait Implementations§
impl Forget for Numbers
impl Freeze for Numbers
impl Move for Numbers
impl RefUnwindSafe for Numbers
impl Send for Numbers
impl Sync for Numbers
impl Unpin for Numbers
impl UnsafeUnpin for Numbers
impl UnwindSafe for Numbers
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more