Debian Codegraph @

src/ext/numeric.rs

raw symbols SCIP
1 #![allow(
2 clippy::cast_possible_truncation,
3 clippy::cast_possible_wrap,
4 clippy::cast_sign_loss,
5 clippy::cast_precision_loss,
6 clippy::float_cmp
7 )]
8
9 use fractionrust-analyzer cargo fraction 0.15.3 crate/::{BigFractionrust-analyzer cargo fraction 0.15.3 prelude/BigFraction#, Onerust-analyzer cargo num-traits 0.2.19 identities/One#, Zerorust-analyzer cargo num-traits 0.2.19 identities/Zero#};
10 use serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::Numberrust-analyzer cargo serde_json 1.0.145 number/Number#;
11
12 macro_rules! define_num_cmprust-analyzer cargo jsonschema 0.37.4 ext/numeric/define_num_cmp! {
13 ($($trait_fn:ident => $fn_name:ident, $op:tt, $infinity_positive:literal),* $(,)?) => {
14 $(
15 pub(crate) fn $fn_name<T>(value: &Number, limit: T) -> bool
16 where
17 T: Copy + num_traits::ToPrimitive,
18 u64: num_cmp::NumCmp<T>,
19 i64: num_cmp::NumCmp<T>,
20 f64: num_cmp::NumCmp<T>,
21 {
22 if let Some(v) = value.as_u64() {
23 num_cmp::NumCmp::$trait_fn(v, limit)
24 } else if let Some(v) = value.as_i64() {
25 num_cmp::NumCmp::$trait_fn(v, limit)
26 } else if let Some(v) = value.as_f64() {
27 num_cmp::NumCmp::$trait_fn(v, limit)
28 } else {
29 #[cfg(feature = "arbitrary-precision")]
30 {
31 if let Some(big_value) = bignum::try_parse_bigfraction(value) {
32 if let Some(limit_f64) = num_traits::ToPrimitive::to_f64(&limit) {
33 let limit_frac = BigFraction::from(limit_f64);
34 return big_value $op limit_frac;
35 }
36 }
37 // Treat unparsable numbers as infinity based on sign
38 let is_negative = value.as_str().starts_with('-');
39 if $infinity_positive {
40 !is_negative
41 } else {
42 is_negative
43 }
44 }
45 #[cfg(not(feature = "arbitrary-precision"))]
46 {
47 unreachable!("Always Some without `arbitrary-precision`")
48 }
49 }
50 }
51 )*
52 };
53 }
54
55 define_num_cmprust-analyzer cargo jsonschema 0.37.4 ext/numeric/define_num_cmp!!(
56 num_gerust-analyzer cargo num-cmp 0.1.0 NumCmp#num_ge(). => gerust-analyzer cargo jsonschema 0.37.4 ext/numeric/ge()., >=, true, // +infinity passes >=, >
57 num_lerust-analyzer cargo num-cmp 0.1.0 NumCmp#num_le(). => lerust-analyzer cargo jsonschema 0.37.4 ext/numeric/le()., <=, false, // -infinity passes <=, <
58 num_gtrust-analyzer cargo num-cmp 0.1.0 NumCmp#num_gt(). => gtrust-analyzer cargo jsonschema 0.37.4 ext/numeric/gt()., >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt()., true,
59 num_ltrust-analyzer cargo num-cmp 0.1.0 NumCmp#num_lt(). => ltrust-analyzer cargo jsonschema 0.37.4 ext/numeric/lt()., <rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt()., false,
60 );
61
62 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn is_multiple_of_floatrust-analyzer cargo jsonschema 0.37.4 ext/numeric/is_multiple_of_float().(value: &Numberrust-analyzer cargo serde_json 1.0.145 number/Number#, multiple: f64) -> bool {
63 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value_f64) = value.as_f64rust-analyzer cargo serde_json 1.0.145 number/impl#[Number]as_f64().() {
64 // Zero is a multiple of any non-zero number
65 // This check must come first to avoid division-related edge cases
66 if value_f64.is_zerorust-analyzer cargo num-traits 0.2.19 identities/impl#[f64][Zero]is_zero().() {
67 return true;
68 }
69 if value_f64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]lt().multiple {
70 return false;
71 }
72 // From the JSON Schema spec
73 //
74 // > A numeric instance is valid only if division by this keyword's value results in an integer.
75 //
76 // For fractions, integers have denominator equal to one.
77 //
78 // Ref: https://json-schema.org/draft/2020-12/json-schema-validation#section-6.2.1
79 (BigFractionrust-analyzer cargo fraction 0.15.3 prelude/BigFraction#::fromrust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`From<f64>`]from().(value_f64) rust-analyzer cargo fraction 0.15.3 fraction/ops/div/impl#[`GenericFraction<T>`][`Div<O>`]div()./rust-analyzer cargo fraction 0.15.3 fraction/ops/div/impl#[`GenericFraction<T>`][`Div<O>`]div(). rust-analyzer cargo fraction 0.15.3 fraction/ops/div/impl#[`GenericFraction<T>`][`Div<O>`]div().BigFractionrust-analyzer cargo fraction 0.15.3 prelude/BigFraction#::fromrust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`From<f64>`]from().(multiple))
80 .denomrust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`]denom().()
81 .is_none_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none_or().(Onerust-analyzer cargo num-traits 0.2.19 identities/One#::is_onerust-analyzer cargo num-bigint 0.4.6 biguint/impl#[BigUint][One]is_one().)
82 } else {
83 // This branch is only possible for large floats in scientific notation, we don't really
84 // support it
85 false
86 }
87 }
88
89 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn is_multiple_of_integerrust-analyzer cargo jsonschema 0.37.4 ext/numeric/is_multiple_of_integer().(value: &Numberrust-analyzer cargo serde_json 1.0.145 number/Number#, multiple: f64) -> bool {
90 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value_f64) = value.as_f64rust-analyzer cargo serde_json 1.0.145 number/impl#[Number]as_f64().() {
91 // As the divisor has its fractional part as zero, then any value with a non-zero
92 // fractional part can't be a multiple of this divisor, therefore it is short-circuited
93 value_f64.fractrust-analyzer cargo std https://github.com/rust-lang/rust/library/std f64/impl#[f64]fract().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]eq().0. && (value_f64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Rem<Self>`]rem().multiple) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]eq().0.
94 } else {
95 // Number doesn't fit in f64 - must be huge with arbitrary_precision
96 #[cfg(feature = "arbitrary-precision")]
97 {
98 // Try parsing as BigInt first for large integers
99 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(big_value) = bignumrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/::try_parse_bigintrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/try_parse_bigint().(value) {
100 use num_bigintrust-analyzer cargo num-bigint 0.4.6 crate/::BigIntrust-analyzer cargo num-bigint 0.4.6 bigint/BigInt#;
101 // Convert the multiple to BigInt.
102 // Note: For large divisors beyond i64/u64 range, the schema compilation
103 // should have created a MultipleOfBigIntValidator instead, which stores
104 // the divisor as BigInt directly. This path handles the case where the
105 // instance is huge but the divisor fits in f64.
106 // Since we know multiple is an integer (checked before calling this function),
107 // we can safely convert via i64 for divisors in the i64 range.
108 // For divisors beyond i64 but representable in f64, precision may be lost,
109 // but that's inherent to f64 representation.
110 let multiple_int = BigIntrust-analyzer cargo num-bigint 0.4.6 bigint/BigInt#::fromrust-analyzer cargo num-bigint 0.4.6 bigint/convert/impl#[BigInt][`From<i64>`]from().(multiple as i64);
111 return bignumrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/::is_multiple_of_bigintrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/is_multiple_of_bigint().(&big_value, &multiple_int);
112 }
113 // Not an integer - can't be a multiple of an integer divisor
114 false
115 }
116 #[cfg(not(feature = "arbitrary-precision"))]
117 {
118 unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!("Always Some without `arbitrary-precision`")
119 }
120 }
121 }
122
123 #[cfg(feature = "arbitrary-precision")]
124 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) mod bignumrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/ {
125 use fractionrust-analyzer cargo fraction 0.15.3 crate/::BigFractionrust-analyzer cargo fraction 0.15.3 prelude/BigFraction#;
126 use num_bigintrust-analyzer cargo num-bigint 0.4.6 crate/::BigIntrust-analyzer cargo num-bigint 0.4.6 bigint/BigInt#;
127 use num_traitsrust-analyzer cargo num-traits 0.2.19 crate/::{ToPrimitiverust-analyzer cargo num-traits 0.2.19 cast/ToPrimitive#, Zerorust-analyzer cargo num-traits 0.2.19 identities/Zero#};
128 use serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::Numberrust-analyzer cargo serde_json 1.0.145 number/Number#;
129 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#;
130
131 /// Guardrail for how many decimal shifts we are willing to perform when normalizing
132 /// a JSON number written in scientific notation.
133 ///
134 /// Schema authors (and instances) are untrusted input: a literal like `"1e1000000000"`
135 /// would otherwise force us to append billions of zeros just to materialize the number,
136 /// opening the door to denial-of-service attacks. Limiting the exponent adjustment to
137 /// one million digits keeps conversions deterministic while still covering realistic
138 /// use-cases (`10^1_000_000` is already astronomically large for JSON Schema).
139 const MAX_EXPONENT_ADJUSTMENTrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/MAX_EXPONENT_ADJUSTMENT.: u32 = 1_000_000;
140
141 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
142 struct DecimalComponentsrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents# {
143 negativerust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents#negative.: bool,
144 digitsrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents#digits.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
145 fraction_digitsrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents#fraction_digits.: usize,
146 exponentrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents#exponent.: i64,
147 }
148
149 impl DecimalComponentsrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents# {
150 fn parserust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/impl#[DecimalComponents]parse().(num_str: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/impl#[DecimalComponents]> {
151 let bytes = num_str.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().();
152 if bytes.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() {
153 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
154 }
155
156 let mut idx = 0;
157 let negative = if bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'-' {
158 idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
159 true
160 } else {
161 false
162 };
163
164 if idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() {
165 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
166 }
167
168 let mut digits = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]with_capacity().(bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().());
169 let int_start = idx;
170 while idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() && bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..is_ascii_digitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u8]is_ascii_digit().() {
171 idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
172 }
173 if int_start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().idx {
174 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
175 }
176 digits.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&num_str[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().int_start..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
177
178 let mut fraction_digits = 0usize;
179 if idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() && bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'.' {
180 idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
181 let frac_start = idx;
182 while idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() && bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..is_ascii_digitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u8]is_ascii_digit().() {
183 idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
184 }
185 if frac_start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().idx {
186 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
187 }
188 digits.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&num_str[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().frac_start..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
189 fraction_digits = idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().frac_start;
190 }
191
192 let mut exponent: i64 = 0;
193 if idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() && (bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'e' || bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'E') {
194 idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
195 if idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() {
196 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
197 }
198 let mut exp_sign: i64 = 1;
199 if bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'+' {
200 idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
201 } else if bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'-' {
202 exp_sign = -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().1;
203 idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
204 }
205 let exp_start = idx;
206 while idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() && bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..is_ascii_digitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u8]is_ascii_digit().() {
207 idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
208 }
209 if exp_start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().idx {
210 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
211 }
212 let exp_value = num_str[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().exp_start..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<i64>().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
213 exponent = exp_value.checked_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i64]checked_mul().(exp_sign)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
214 }
215
216 if idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() {
217 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
218 }
219
220 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Selfrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/impl#[DecimalComponents] {
221 negativerust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents#negative.,
222 digitsrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents#digits.,
223 fraction_digitsrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents#fraction_digits.,
224 exponentrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents#exponent.,
225 })
226 }
227
228 #[inline]
229 fn decimal_shiftrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/impl#[DecimalComponents]decimal_shift().(&self) -> i64 {
230 self.exponentrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents#exponent. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Sub<Self>`]sub().self.fraction_digitsrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents#fraction_digits. as i64
231 }
232 }
233
234 fn digits_are_zerorust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/digits_are_zero().(s: &str) -> bool {
235 s.bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]bytes().().allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Bytes<'_>`][Iterator]all().(|b| b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'0')
236 }
237
238 fn trailing_zero_countrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/trailing_zero_count().(s: &str) -> usize {
239 s.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()
240 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
241 .revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().()
242 .take_whilerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take_while().(|b| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'0')
243 .countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().()
244 }
245
246 fn append_zerosrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/append_zeros().(target: &mut Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, count: usize) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<()> {
247 let new_len = target.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().().checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_add().(count)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
248 target.reserverust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]reserve().(count);
249 target.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Extend<char>`]extend().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::repeat_nrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/repeat_n/repeat_n().('0', count));
250 debug_assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert_eq!!(target.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().(), new_len);
251 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(())
252 }
253
254 fn pow10_bigintrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/pow10_bigint().(exp: usize) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<BigIntrust-analyzer cargo num-bigint 0.4.6 bigint/BigInt#> {
255 if exp rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 {
256 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(BigIntrust-analyzer cargo num-bigint 0.4.6 bigint/BigInt#::fromrust-analyzer cargo num-bigint 0.4.6 bigint/convert/impl#[BigInt][`From<i32>`]from().(1));
257 }
258 let exp_u32 = u32::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[u32][`TryFrom<usize>`]try_from().(exp).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
259 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(BigIntrust-analyzer cargo num-bigint 0.4.6 bigint/BigInt#::fromrust-analyzer cargo num-bigint 0.4.6 bigint/convert/impl#[BigInt][`From<i32>`]from().(10).powrust-analyzer cargo num-bigint 0.4.6 bigint/impl#[BigInt]pow().(exp_u32))
260 }
261
262 fn shift_exceeds_limitrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/shift_exceeds_limit().(shift: i64) -> bool {
263 if shift rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le().0 {
264 return false;
265 }
266 shift as u64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u32>`]from().(MAX_EXPONENT_ADJUSTMENTrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/MAX_EXPONENT_ADJUSTMENT.)
267 }
268
269 fn exponent_reduction_exceeds_limitrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/exponent_reduction_exceeds_limit().(exponent: i64) -> bool {
270 if exponent rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]ge().0 {
271 return false;
272 }
273 match exponent.checked_absrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i64]checked_abs().() {
274 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(abs) => abs as u64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u32>`]from().(MAX_EXPONENT_ADJUSTMENTrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/MAX_EXPONENT_ADJUSTMENT.),
275 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => true,
276 }
277 }
278
279 /// Try to parse a Number as `BigInt` if it's outside i64 range or for compile-time
280 /// schema values that need exact representation
281 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn try_parse_bigintrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/try_parse_bigint().(num: &Numberrust-analyzer cargo serde_json 1.0.145 number/Number#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<BigIntrust-analyzer cargo num-bigint 0.4.6 bigint/BigInt#> {
282 let num_str = num.as_strrust-analyzer cargo serde_json 1.0.145 number/impl#[Number]as_str().();
283
284 // Only parse as BigInt if it doesn't fit in i64
285 // We include u64 values beyond i64::MAX because they can't be accurately
286 // represented when cast to i64, which is needed for certain operations
287 if num.as_i64rust-analyzer cargo serde_json 1.0.145 number/impl#[Number]as_i64().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
288 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
289 }
290
291 let has_fraction_or_exponent = num_str.bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]bytes().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Bytes<'_>`][Iterator]any().(|b| b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'.' || b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'e' || b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'E');
292 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().has_fraction_or_exponent {
293 return BigIntrust-analyzer cargo num-bigint 0.4.6 bigint/BigInt#::from_strrust-analyzer cargo num-bigint 0.4.6 bigint/convert/impl#[BigInt][FromStr]from_str().(num_str).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().();
294 }
295
296 let mut components = DecimalComponentsrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents#::parserust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/impl#[DecimalComponents]parse().(num_str)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
297 let mut shift = components.decimal_shiftrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/impl#[DecimalComponents]decimal_shift().();
298
299 if shift rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]lt().0 {
300 let needed = (-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().shift) as usize;
301 if digits_are_zerorust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/digits_are_zero().(&components.digitsrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents#digits.) {
302 components.digitsrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents#digits..clearrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]clear().();
303 components.digitsrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents#digits..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('0');
304 shift = 0;
305 } else {
306 if exponent_reduction_exceeds_limitrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/exponent_reduction_exceeds_limit().(components.exponentrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents#exponent.) {
307 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
308 }
309 let zeros = trailing_zero_countrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/trailing_zero_count().(&components.digitsrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents#digits.);
310 if zeros rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().needed {
311 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
312 }
313 let new_len = components.digitsrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents#digits..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().needed;
314 components.digitsrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents#digits..truncaterust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]truncate().(new_len);
315 shift = 0;
316 }
317 }
318
319 if shift rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]gt().0 {
320 if shift_exceeds_limitrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/shift_exceeds_limit().(shift) {
321 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
322 }
323 append_zerosrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/append_zeros().(&mut components.digitsrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents#digits., shift as usize)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
324 }
325
326 let digits_trimmed = components.digitsrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents#digits..trim_start_matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_start_matches().('0');
327 let digits_ref = if digits_trimmed.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() {
328 "0"
329 } else {
330 digits_trimmed
331 };
332 let mut value = BigIntrust-analyzer cargo num-bigint 0.4.6 bigint/BigInt#::from_strrust-analyzer cargo num-bigint 0.4.6 bigint/convert/impl#[BigInt][FromStr]from_str().(digits_ref).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
333 if components.negativerust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents#negative. && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().value.is_zerorust-analyzer cargo num-bigint 0.4.6 bigint/impl#[BigInt][Zero]is_zero().() {
334 value = -rust-analyzer cargo num-bigint 0.4.6 bigint/impl#[BigInt][Neg]neg().value;
335 }
336 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value)
337 }
338
339 /// Try to parse a Number as `BigFraction` for arbitrary precision decimal support
340 ///
341 /// Returns Some for numbers requiring exact decimal precision:
342 /// - Decimals with a decimal point (e.g., `0.1`, `123.456`)
343 /// - Scientific notation decimals that can't be represented exactly as f64
344 ///
345 /// Returns None for:
346 /// - Integers that fit in i64 (handled by standard numeric path)
347 /// - Large integers including u64 beyond `i64::MAX` (handled by `try_parse_bigint`)
348 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn try_parse_bigfractionrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/try_parse_bigfraction().(num: &Numberrust-analyzer cargo serde_json 1.0.145 number/Number#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<BigFractionrust-analyzer cargo fraction 0.15.3 prelude/BigFraction#> {
349 // Skip integers that fit in i64 - they don't need BigFraction
350 if num.as_i64rust-analyzer cargo serde_json 1.0.145 number/impl#[Number]as_i64().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
351 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
352 }
353
354 let num_str = num.as_strrust-analyzer cargo serde_json 1.0.145 number/impl#[Number]as_str().();
355
356 // Check for decimal point and exponent in a single pass
357 let mut has_decimal_point = false;
358 let mut has_exponent = false;
359 for b in num_str.bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]bytes().() {
360 if b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'.' {
361 has_decimal_point = true;
362 } else if b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'e' || b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'E' {
363 has_exponent = true;
364 break;
365 }
366 }
367
368 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().has_decimal_point && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().has_exponent {
369 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
370 }
371
372 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().has_exponent {
373 return BigFractionrust-analyzer cargo fraction 0.15.3 prelude/BigFraction#::from_strrust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][FromStr]from_str().(num_str).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().();
374 }
375
376 let components = DecimalComponentsrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents#::parserust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/impl#[DecimalComponents]parse().(num_str)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
377 let shift = components.decimal_shiftrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/impl#[DecimalComponents]decimal_shift().();
378
379 // A number with exponent that still resolves to an integer is handled by BigInt.
380 if shift rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]ge().0 {
381 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
382 }
383
384 if exponent_reduction_exceeds_limitrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/exponent_reduction_exceeds_limit().(components.exponentrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents#exponent.) {
385 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
386 }
387
388 let denom_power = (-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().shift) as usize;
389 let denominator = pow10_bigintrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/pow10_bigint().(denom_power)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
390 let mut numerator = BigIntrust-analyzer cargo num-bigint 0.4.6 bigint/BigInt#::from_strrust-analyzer cargo num-bigint 0.4.6 bigint/convert/impl#[BigInt][FromStr]from_str().(&components.digitsrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents#digits.).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
391 if components.negativerust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/DecimalComponents#negative. && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().numerator.is_zerorust-analyzer cargo num-bigint 0.4.6 bigint/impl#[BigInt][Zero]is_zero().() {
392 numerator = -rust-analyzer cargo num-bigint 0.4.6 bigint/impl#[BigInt][Neg]neg().numerator;
393 }
394 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(BigFractionrust-analyzer cargo fraction 0.15.3 prelude/BigFraction#::fromrust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`From<BigInt>`]from().(numerator) rust-analyzer cargo fraction 0.15.3 fraction/ops/div/impl#[`GenericFraction<T>`][`Div<O>`]div()./rust-analyzer cargo fraction 0.15.3 fraction/ops/div/impl#[`GenericFraction<T>`][`Div<O>`]div(). rust-analyzer cargo fraction 0.15.3 fraction/ops/div/impl#[`GenericFraction<T>`][`Div<O>`]div().BigFractionrust-analyzer cargo fraction 0.15.3 prelude/BigFraction#::fromrust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`From<BigInt>`]from().(denominator))
395 }
396
397 macro_rules! define_bigint_cmprust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/define_bigint_cmp! {
398 ($($fn_name:ident, $prim_type:ty, $to_prim:ident, $op:tt, $overflow_sign:expr);* $(;)?) => {
399 $(
400 pub(crate) fn $fn_name(bigint: &BigInt, value: $prim_type) -> bool {
401 if let Some(converted) = bigint.$to_prim() {
402 converted $op value
403 } else {
404 bigint.sign() == $overflow_sign
405 }
406 }
407 )*
408 };
409 }
410
411 define_bigint_cmprust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/define_bigint_cmp!!(
412 bigint_ge_u64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigint_ge_u64()., u64, to_u64rust-analyzer cargo num-bigint 0.4.6 bigint/convert/impl#[BigInt][ToPrimitive]to_u64()., >=, num_bigintrust-analyzer cargo num-bigint 0.4.6 crate/::Signrust-analyzer cargo num-bigint 0.4.6 bigint/Sign#::Plusrust-analyzer cargo num-bigint 0.4.6 bigint/Sign#Plus#;
413 bigint_le_u64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigint_le_u64()., u64, to_u64rust-analyzer cargo num-bigint 0.4.6 bigint/convert/impl#[BigInt][ToPrimitive]to_u64()., <=, num_bigintrust-analyzer cargo num-bigint 0.4.6 crate/::Signrust-analyzer cargo num-bigint 0.4.6 bigint/Sign#::Minusrust-analyzer cargo num-bigint 0.4.6 bigint/Sign#Minus#;
414 bigint_gt_u64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigint_gt_u64()., u64, to_u64rust-analyzer cargo num-bigint 0.4.6 bigint/convert/impl#[BigInt][ToPrimitive]to_u64()., >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt()., num_bigintrust-analyzer cargo num-bigint 0.4.6 crate/::Signrust-analyzer cargo num-bigint 0.4.6 bigint/Sign#::Plusrust-analyzer cargo num-bigint 0.4.6 bigint/Sign#Plus#;
415 bigint_lt_u64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigint_lt_u64()., u64, to_u64rust-analyzer cargo num-bigint 0.4.6 bigint/convert/impl#[BigInt][ToPrimitive]to_u64()., <rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]lt()., num_bigintrust-analyzer cargo num-bigint 0.4.6 crate/::Signrust-analyzer cargo num-bigint 0.4.6 bigint/Sign#::Minusrust-analyzer cargo num-bigint 0.4.6 bigint/Sign#Minus#;
416 bigint_ge_i64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigint_ge_i64()., i64, to_i64rust-analyzer cargo num-bigint 0.4.6 bigint/convert/impl#[BigInt][ToPrimitive]to_i64()., >=, num_bigintrust-analyzer cargo num-bigint 0.4.6 crate/::Signrust-analyzer cargo num-bigint 0.4.6 bigint/Sign#::Plusrust-analyzer cargo num-bigint 0.4.6 bigint/Sign#Plus#;
417 bigint_le_i64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigint_le_i64()., i64, to_i64rust-analyzer cargo num-bigint 0.4.6 bigint/convert/impl#[BigInt][ToPrimitive]to_i64()., <=, num_bigintrust-analyzer cargo num-bigint 0.4.6 crate/::Signrust-analyzer cargo num-bigint 0.4.6 bigint/Sign#::Minusrust-analyzer cargo num-bigint 0.4.6 bigint/Sign#Minus#;
418 bigint_gt_i64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigint_gt_i64()., i64, to_i64rust-analyzer cargo num-bigint 0.4.6 bigint/convert/impl#[BigInt][ToPrimitive]to_i64()., >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]gt()., num_bigintrust-analyzer cargo num-bigint 0.4.6 crate/::Signrust-analyzer cargo num-bigint 0.4.6 bigint/Sign#::Plusrust-analyzer cargo num-bigint 0.4.6 bigint/Sign#Plus#;
419 bigint_lt_i64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigint_lt_i64()., i64, to_i64rust-analyzer cargo num-bigint 0.4.6 bigint/convert/impl#[BigInt][ToPrimitive]to_i64()., <rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]lt()., num_bigintrust-analyzer cargo num-bigint 0.4.6 crate/::Signrust-analyzer cargo num-bigint 0.4.6 bigint/Sign#::Minusrust-analyzer cargo num-bigint 0.4.6 bigint/Sign#Minus#;
420 bigint_ge_f64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigint_ge_f64()., f64, to_f64rust-analyzer cargo num-bigint 0.4.6 bigint/convert/impl#[BigInt][ToPrimitive]to_f64()., >=, num_bigintrust-analyzer cargo num-bigint 0.4.6 crate/::Signrust-analyzer cargo num-bigint 0.4.6 bigint/Sign#::Plusrust-analyzer cargo num-bigint 0.4.6 bigint/Sign#Plus#;
421 bigint_le_f64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigint_le_f64()., f64, to_f64rust-analyzer cargo num-bigint 0.4.6 bigint/convert/impl#[BigInt][ToPrimitive]to_f64()., <=, num_bigintrust-analyzer cargo num-bigint 0.4.6 crate/::Signrust-analyzer cargo num-bigint 0.4.6 bigint/Sign#::Minusrust-analyzer cargo num-bigint 0.4.6 bigint/Sign#Minus#;
422 bigint_gt_f64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigint_gt_f64()., f64, to_f64rust-analyzer cargo num-bigint 0.4.6 bigint/convert/impl#[BigInt][ToPrimitive]to_f64()., >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]gt()., num_bigintrust-analyzer cargo num-bigint 0.4.6 crate/::Signrust-analyzer cargo num-bigint 0.4.6 bigint/Sign#::Plusrust-analyzer cargo num-bigint 0.4.6 bigint/Sign#Plus#;
423 bigint_lt_f64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigint_lt_f64()., f64, to_f64rust-analyzer cargo num-bigint 0.4.6 bigint/convert/impl#[BigInt][ToPrimitive]to_f64()., <rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]lt()., num_bigintrust-analyzer cargo num-bigint 0.4.6 crate/::Signrust-analyzer cargo num-bigint 0.4.6 bigint/Sign#::Minusrust-analyzer cargo num-bigint 0.4.6 bigint/Sign#Minus#;
424 );
425
426 // Generate reverse comparison functions (primitive op BigType -> BigType op primitive)
427 macro_rules! define_reverse_cmprust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/define_reverse_cmp! {
428 ($($rev_ge:ident, $rev_le:ident, $rev_gt:ident, $rev_lt:ident, $prim_type:ty, $big_type:ty, $fwd_ge:ident, $fwd_le:ident, $fwd_gt:ident, $fwd_lt:ident);* $(;)?) => {
429 $(
430 pub(crate) fn $rev_ge(value: $prim_type, big: &$big_type) -> bool {
431 $fwd_le(big, value)
432 }
433
434 pub(crate) fn $rev_le(value: $prim_type, big: &$big_type) -> bool {
435 $fwd_ge(big, value)
436 }
437
438 pub(crate) fn $rev_gt(value: $prim_type, big: &$big_type) -> bool {
439 $fwd_lt(big, value)
440 }
441
442 pub(crate) fn $rev_lt(value: $prim_type, big: &$big_type) -> bool {
443 $fwd_gt(big, value)
444 }
445 )*
446 };
447 }
448
449 define_reverse_cmprust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/define_reverse_cmp!!(
450 u64_ge_bigintrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/u64_ge_bigint()., u64_le_bigintrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/u64_le_bigint()., u64_gt_bigintrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/u64_gt_bigint()., u64_lt_bigintrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/u64_lt_bigint()., u64, BigIntrust-analyzer cargo num-bigint 0.4.6 bigint/BigInt#, bigint_ge_u64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigint_ge_u64()., bigint_le_u64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigint_le_u64()., bigint_gt_u64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigint_gt_u64()., bigint_lt_u64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigint_lt_u64().;
451 i64_ge_bigintrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/i64_ge_bigint()., i64_le_bigintrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/i64_le_bigint()., i64_gt_bigintrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/i64_gt_bigint()., i64_lt_bigintrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/i64_lt_bigint()., i64, BigIntrust-analyzer cargo num-bigint 0.4.6 bigint/BigInt#, bigint_ge_i64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigint_ge_i64()., bigint_le_i64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigint_le_i64()., bigint_gt_i64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigint_gt_i64()., bigint_lt_i64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigint_lt_i64().;
452 f64_ge_bigintrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/f64_ge_bigint()., f64_le_bigintrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/f64_le_bigint()., f64_gt_bigintrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/f64_gt_bigint()., f64_lt_bigintrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/f64_lt_bigint()., f64, BigIntrust-analyzer cargo num-bigint 0.4.6 bigint/BigInt#, bigint_ge_f64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigint_ge_f64()., bigint_le_f64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigint_le_f64()., bigint_gt_f64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigint_gt_f64()., bigint_lt_f64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigint_lt_f64().;
453 );
454
455 /// Check if a Number (as `BigInt`) is a multiple of another `BigInt`
456 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn is_multiple_of_bigintrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/is_multiple_of_bigint().(value: &BigIntrust-analyzer cargo num-bigint 0.4.6 bigint/BigInt#, multiple: &BigIntrust-analyzer cargo num-bigint 0.4.6 bigint/BigInt#) -> bool {
457 // Zero is a multiple of any non-zero number
458 // Mathematically: 0 = k * multiple for k = 0
459 if value.is_zerorust-analyzer cargo num-bigint 0.4.6 bigint/impl#[BigInt][Zero]is_zero().() {
460 return true;
461 }
462
463 // Note: multiple.is_zero() case is not handled here because JSON Schema
464 // validation rejects schemas with "multipleOf: 0" during compilation
465 // (exclusiveMinimum constraint requires multipleOf > 0).
466 // The modulo operation below would panic if multiple is zero, but this
467 // is prevented by schema validation.
468
469 (value rust-analyzer cargo num-bigint 0.4.6 bigint/division/impl#[`&BigInt`][`Rem<Self>`]rem().%rust-analyzer cargo num-bigint 0.4.6 bigint/division/impl#[`&BigInt`][`Rem<Self>`]rem(). rust-analyzer cargo num-bigint 0.4.6 bigint/division/impl#[`&BigInt`][`Rem<Self>`]rem().multiple).is_zerorust-analyzer cargo num-bigint 0.4.6 bigint/impl#[BigInt][Zero]is_zero().()
470 }
471
472 // BigFraction comparison functions
473 macro_rules! define_bigfraction_cmprust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/define_bigfraction_cmp! {
474 ($($fn_name:ident, $prim_type:ty, $op:tt);* $(;)?) => {
475 $(
476 pub(crate) fn $fn_name(bigfrac: &BigFraction, value: $prim_type) -> bool {
477 let value_frac = BigFraction::from(value);
478 *bigfrac $op value_frac
479 }
480 )*
481 };
482 }
483
484 define_bigfraction_cmprust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/define_bigfraction_cmp!!(
485 bigfrac_ge_u64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigfrac_ge_u64()., u64, >=;
486 bigfrac_le_u64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigfrac_le_u64()., u64, <=;
487 bigfrac_gt_u64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigfrac_gt_u64()., u64, >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt().;
488 bigfrac_lt_u64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigfrac_lt_u64()., u64, <rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt().;
489 bigfrac_ge_i64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigfrac_ge_i64()., i64, >=;
490 bigfrac_le_i64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigfrac_le_i64()., i64, <=;
491 bigfrac_gt_i64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigfrac_gt_i64()., i64, >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt().;
492 bigfrac_lt_i64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigfrac_lt_i64()., i64, <rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt().;
493 bigfrac_ge_f64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigfrac_ge_f64()., f64, >=;
494 bigfrac_le_f64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigfrac_le_f64()., f64, <=;
495 bigfrac_gt_f64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigfrac_gt_f64()., f64, >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt().;
496 bigfrac_lt_f64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigfrac_lt_f64()., f64, <rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt().;
497 );
498
499 define_reverse_cmprust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/define_reverse_cmp!!(
500 u64_ge_bigfracrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/u64_ge_bigfrac()., u64_le_bigfracrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/u64_le_bigfrac()., u64_gt_bigfracrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/u64_gt_bigfrac()., u64_lt_bigfracrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/u64_lt_bigfrac()., u64, BigFractionrust-analyzer cargo fraction 0.15.3 prelude/BigFraction#, bigfrac_ge_u64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigfrac_ge_u64()., bigfrac_le_u64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigfrac_le_u64()., bigfrac_gt_u64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigfrac_gt_u64()., bigfrac_lt_u64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigfrac_lt_u64().;
501 i64_ge_bigfracrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/i64_ge_bigfrac()., i64_le_bigfracrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/i64_le_bigfrac()., i64_gt_bigfracrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/i64_gt_bigfrac()., i64_lt_bigfracrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/i64_lt_bigfrac()., i64, BigFractionrust-analyzer cargo fraction 0.15.3 prelude/BigFraction#, bigfrac_ge_i64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigfrac_ge_i64()., bigfrac_le_i64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigfrac_le_i64()., bigfrac_gt_i64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigfrac_gt_i64()., bigfrac_lt_i64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigfrac_lt_i64().;
502 f64_ge_bigfracrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/f64_ge_bigfrac()., f64_le_bigfracrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/f64_le_bigfrac()., f64_gt_bigfracrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/f64_gt_bigfrac()., f64_lt_bigfracrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/f64_lt_bigfrac()., f64, BigFractionrust-analyzer cargo fraction 0.15.3 prelude/BigFraction#, bigfrac_ge_f64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigfrac_ge_f64()., bigfrac_le_f64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigfrac_le_f64()., bigfrac_gt_f64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigfrac_gt_f64()., bigfrac_lt_f64rust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/bigfrac_lt_f64().;
503 );
504
505 /// Check if a `BigFraction` is a multiple of another value
506 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn is_multiple_of_bigfracrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/is_multiple_of_bigfrac().(value: &BigFractionrust-analyzer cargo fraction 0.15.3 prelude/BigFraction#, multiple: &BigFractionrust-analyzer cargo fraction 0.15.3 prelude/BigFraction#) -> bool {
507 // Zero is a multiple of any non-zero number
508 if value.is_zerorust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][Zero]is_zero().() {
509 return true;
510 }
511 // Division by zero is undefined, so return false
512 if multiple.is_zerorust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][Zero]is_zero().() {
513 return false;
514 }
515 // A number is a multiple of another if division results in an integer
516 // (denominator of the result is 1)
517 (value rust-analyzer cargo fraction 0.15.3 fraction/ops/div/impl#[`&'a GenericFraction<T>`][`Div<Self>`]div()./rust-analyzer cargo fraction 0.15.3 fraction/ops/div/impl#[`&'a GenericFraction<T>`][`Div<Self>`]div(). rust-analyzer cargo fraction 0.15.3 fraction/ops/div/impl#[`&'a GenericFraction<T>`][`Div<Self>`]div().multiple).denomrust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`]denom().().is_none_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none_or().(fractionrust-analyzer cargo fraction 0.15.3 crate/::Onerust-analyzer cargo num-traits 0.2.19 identities/One#::is_onerust-analyzer cargo num-bigint 0.4.6 biguint/impl#[BigUint][One]is_one().)
518 }
519 }
520
521 #[cfg(all(test, feature = "arbitrary-precision"))]
522 mod testsrust-analyzer cargo jsonschema 0.37.4 ext/numeric/tests/ {
523 use superrust-analyzer cargo jsonschema 0.37.4 ext/numeric/::bignumrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/;
524 use fractionrust-analyzer cargo fraction 0.15.3 crate/::BigFractionrust-analyzer cargo fraction 0.15.3 prelude/BigFraction#;
525 use num_bigintrust-analyzer cargo num-bigint 0.4.6 crate/::BigIntrust-analyzer cargo num-bigint 0.4.6 bigint/BigInt#;
526 use serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::{Numberrust-analyzer cargo serde_json 1.0.145 number/Number#, Valuerust-analyzer cargo serde_json 1.0.145 value/Value#};
527 use test_caserust-analyzer cargo test-case 3.3.1 crate/::test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:;
528
529 fn number_from_strrust-analyzer cargo jsonschema 0.37.4 ext/numeric/tests/number_from_str().(raw: &str) -> Numberrust-analyzer cargo serde_json 1.0.145 number/Number# {
530 match serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::from_strrust-analyzer cargo serde_json 1.0.145 de/from_str().::<Valuerust-analyzer cargo serde_json 1.0.145 value/Value#>(raw).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("valid JSON number") {
531 Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Numberrust-analyzer cargo serde_json 1.0.145 value/Value#Number#(num) => num,
532 _ => unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!(),
533 }
534 }
535
536 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
537 fn bigint_parses_scientific_integerrust-analyzer cargo jsonschema 0.37.4 ext/numeric/tests/bigint_parses_scientific_integer().() {
538 let num = number_from_strrust-analyzer cargo jsonschema 0.37.4 ext/numeric/tests/number_from_str().("1e19");
539 let parsed = bignumrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/::try_parse_bigintrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/try_parse_bigint().(&num).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("parsed bigint");
540 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
541 parsed,
542 BigIntrust-analyzer cargo num-bigint 0.4.6 bigint/BigInt#::parse_bytesrust-analyzer cargo num-bigint 0.4.6 bigint/impl#[BigInt]parse_bytes().(b"10000000000000000000", 10).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
543 );
544 }
545
546 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
547 fn bigint_rejects_non_integer_scientificrust-analyzer cargo jsonschema 0.37.4 ext/numeric/tests/bigint_rejects_non_integer_scientific().() {
548 let num = number_from_strrust-analyzer cargo jsonschema 0.37.4 ext/numeric/tests/number_from_str().("1.25e1");
549 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(bignumrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/::try_parse_bigintrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/try_parse_bigint().(&num).is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().());
550 }
551
552 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
553 fn bigfraction_parses_scientific_decimalrust-analyzer cargo jsonschema 0.37.4 ext/numeric/tests/bigfraction_parses_scientific_decimal().() {
554 let num = number_from_strrust-analyzer cargo jsonschema 0.37.4 ext/numeric/tests/number_from_str().("1.5e-5");
555 let parsed = bignumrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/::try_parse_bigfractionrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/try_parse_bigfraction().(&num).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("parsed bigfraction");
556 let expected =
557 BigFractionrust-analyzer cargo fraction 0.15.3 prelude/BigFraction#::fromrust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`From<BigInt>`]from().(BigIntrust-analyzer cargo num-bigint 0.4.6 bigint/BigInt#::fromrust-analyzer cargo num-bigint 0.4.6 bigint/convert/impl#[BigInt][`From<i32>`]from().(3)) rust-analyzer cargo fraction 0.15.3 fraction/ops/div/impl#[`GenericFraction<T>`][`Div<O>`]div()./rust-analyzer cargo fraction 0.15.3 fraction/ops/div/impl#[`GenericFraction<T>`][`Div<O>`]div(). rust-analyzer cargo fraction 0.15.3 fraction/ops/div/impl#[`GenericFraction<T>`][`Div<O>`]div().BigFractionrust-analyzer cargo fraction 0.15.3 prelude/BigFraction#::fromrust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`From<BigInt>`]from().(BigIntrust-analyzer cargo num-bigint 0.4.6 bigint/BigInt#::fromrust-analyzer cargo num-bigint 0.4.6 bigint/convert/impl#[BigInt][`From<i32>`]from().(200_000));
558 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parsed, expected);
559 }
560
561 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
562 fn bigfraction_skips_scientific_integerrust-analyzer cargo jsonschema 0.37.4 ext/numeric/tests/bigfraction_skips_scientific_integer().() {
563 let num = number_from_strrust-analyzer cargo jsonschema 0.37.4 ext/numeric/tests/number_from_str().("3e4");
564 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(bignumrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/::try_parse_bigfractionrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/try_parse_bigfraction().(&num).is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().());
565 }
566
567 // Huge decimal beyond f64 range
568 const HUGE_POSITIVErust-analyzer cargo jsonschema 0.37.4 ext/numeric/tests/HUGE_POSITIVE.: &str = "99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.5";
569 const HUGE_NEGATIVErust-analyzer cargo jsonschema 0.37.4 ext/numeric/tests/HUGE_NEGATIVE.: &str = "-99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.5";
570
571 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(r#"{"minimum": 0}"#, HUGE_POSITIVErust-analyzer cargo jsonschema 0.37.4 ext/numeric/tests/HUGE_POSITIVE., true ; "huge_positive_vs_minimum_0")]
572 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(r#"{"minimum": 0}"#, HUGE_NEGATIVErust-analyzer cargo jsonschema 0.37.4 ext/numeric/tests/HUGE_NEGATIVE., false ; "huge_negative_vs_minimum_0")]
573 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(r#"{"maximum": 1000}"#, HUGE_POSITIVErust-analyzer cargo jsonschema 0.37.4 ext/numeric/tests/HUGE_POSITIVE., false ; "huge_positive_vs_maximum_1000")]
574 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(r#"{"maximum": 0}"#, HUGE_NEGATIVErust-analyzer cargo jsonschema 0.37.4 ext/numeric/tests/HUGE_NEGATIVE., true ; "huge_negative_vs_maximum_0")]
575 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(r#"{"exclusiveMinimum": 0}"#, HUGE_POSITIVErust-analyzer cargo jsonschema 0.37.4 ext/numeric/tests/HUGE_POSITIVE., true ; "huge_positive_vs_exclusive_minimum_0")]
576 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(r#"{"exclusiveMinimum": 0}"#, HUGE_NEGATIVErust-analyzer cargo jsonschema 0.37.4 ext/numeric/tests/HUGE_NEGATIVE., false ; "huge_negative_vs_exclusive_minimum_0")]
577 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(r#"{"exclusiveMaximum": 1000}"#, HUGE_POSITIVErust-analyzer cargo jsonschema 0.37.4 ext/numeric/tests/HUGE_POSITIVE., false ; "huge_positive_vs_exclusive_maximum_1000")]
578 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(r#"{"exclusiveMaximum": 0}"#, HUGE_NEGATIVErust-analyzer cargo jsonschema 0.37.4 ext/numeric/tests/HUGE_NEGATIVE., true ; "huge_negative_vs_exclusive_maximum_0")]
579 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(r#"{"minimum": -1000, "maximum": 1000}"#, HUGE_POSITIVErust-analyzer cargo jsonschema 0.37.4 ext/numeric/tests/HUGE_POSITIVE., false ; "huge_positive_outside_range")]
580 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(r#"{"minimum": -1000, "maximum": 1000}"#, HUGE_NEGATIVErust-analyzer cargo jsonschema 0.37.4 ext/numeric/tests/HUGE_NEGATIVE., false ; "huge_negative_outside_range")]
581 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(r#"{"multipleOf": 0.5}"#, HUGE_POSITIVErust-analyzer cargo jsonschema 0.37.4 ext/numeric/tests/HUGE_POSITIVE., true ; "huge_positive_multiple_of_0_5")]
582 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(r#"{"multipleOf": 0.5}"#, HUGE_NEGATIVErust-analyzer cargo jsonschema 0.37.4 ext/numeric/tests/HUGE_NEGATIVE., true ; "huge_negative_multiple_of_0_5")]
583 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(r#"{"multipleOf": 2}"#, HUGE_POSITIVErust-analyzer cargo jsonschema 0.37.4 ext/numeric/tests/HUGE_POSITIVE., false ; "huge_positive_not_multiple_of_2")]
584 fn test_huge_decimal_validationrust-analyzer cargo jsonschema 0.37.4 ext/numeric/tests/test_huge_decimal_validation().(schema_json: &str, instance_value: &str, expected_valid: bool) {
585 let schema: serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::Valuerust-analyzer cargo serde_json 1.0.145 value/Value# = serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::from_strrust-analyzer cargo serde_json 1.0.145 de/from_str().(schema_json).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
586 let validator = craterust-analyzer cargo jsonschema 0.37.4 crate/::validator_forrust-analyzer cargo jsonschema 0.37.4 validator_for().(&schema).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
587 let instance = serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::from_strrust-analyzer cargo serde_json 1.0.145 de/from_str().(instance_value).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
588
589 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(validator.is_validrust-analyzer cargo jsonschema 0.37.4 validator/impl#[Validator]is_valid().(&instance), expected_valid);
590 }
591 }