| 1 | use rust_decimalrust-analyzer cargo rust_decimal 1.42.1 crate/::Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal#; |
| 2 | |
| 3 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::decoderust-analyzer cargo sqlx-core 0.8.3 decode/::Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#; |
| 4 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::encoderust-analyzer cargo sqlx-core 0.8.3 encode/::{Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#, IsNullrust-analyzer cargo sqlx-core 0.8.3 encode/IsNull#}; |
| 5 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::errorrust-analyzer cargo sqlx-postgres 0.8.3 error/::BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#; |
| 6 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::typesrust-analyzer cargo sqlx-postgres 0.8.3 types/::numericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/::{PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#, PgNumericSignrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#}; |
| 7 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::typesrust-analyzer cargo sqlx-postgres 0.8.3 types/::Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#; |
| 8 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::{PgArgumentBufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#, PgHasArrayTyperust-analyzer cargo sqlx-postgres 0.8.3 types/array/PgHasArrayType#, PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#, PgValueFormatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#, PgValueRefrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#}; |
| 9 | |
| 10 | use rust_decimalrust-analyzer cargo rust_decimal 1.42.1 crate/::MathematicalOpsrust-analyzer cargo rust_decimal 1.42.1 maths/MathematicalOps#; |
| 11 | |
| 12 | impl Typerust-analyzer cargo sqlx-core 0.8.3 types/Type#<Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal# { |
| 13 | fn type_inforust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/impl#[Decimal][`Type<Postgres>`]type_info().() -> PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo# { |
| 14 | PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#::NUMERICrust-analyzer cargo sqlx-postgres 0.8.3 type_info/impl#[PgTypeInfo]NUMERIC. |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | impl PgHasArrayTyperust-analyzer cargo sqlx-postgres 0.8.3 types/array/PgHasArrayType# for Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal# { |
| 19 | fn array_type_inforust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/impl#[Decimal][PgHasArrayType]array_type_info().() -> PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo# { |
| 20 | PgTypeInforust-analyzer cargo sqlx-postgres 0.8.3 type_info/PgTypeInfo#::NUMERIC_ARRAYrust-analyzer cargo sqlx-postgres 0.8.3 type_info/impl#[PgTypeInfo]NUMERIC_ARRAY. |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#> for Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal# { |
| 25 | type Errorrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/impl#[Decimal][`TryFrom<PgNumeric>`]Error# = BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#; |
| 26 | |
| 27 | fn try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/impl#[Decimal][`TryFrom<PgNumeric>`]try_from().(numeric: PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/impl#[Decimal][`TryFrom<PgNumeric>`], BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> { |
| 28 | Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal#::try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/impl#[Decimal][`TryFrom<&PgNumeric>`]try_from().(&numeric) |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<&'_ PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#> for Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal# { |
| 33 | type Errorrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/impl#[Decimal][`TryFrom<&PgNumeric>`]Error# = BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#; |
| 34 | |
| 35 | fn try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/impl#[Decimal][`TryFrom<&PgNumeric>`]try_from().(numeric: &'_ PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/impl#[Decimal][`TryFrom<&PgNumeric>`], BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> { |
| 36 | let (digits, sign, mut weight, scale) = match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().numeric { |
| 37 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::Numberrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number# { |
| 38 | ref digitsrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#digits., |
| 39 | signrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#sign., |
| 40 | weightrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#weight., |
| 41 | scalerust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#scale., |
| 42 | } => (digits, sign, weight, scale), |
| 43 | |
| 44 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::NotANumberrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#NotANumber# => { |
| 45 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("Decimal does not support NaN values".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | if digits.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 50 | // Postgres returns an empty digit array for 0 |
| 51 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal#::ZEROrust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]ZERO.); |
| 52 | } |
| 53 | |
| 54 | let scale = u32::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u32][`TryFrom<i16>`]try_from().(scale) |
| 55 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("invalid scale value for Pg NUMERIC: {scale}"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 56 | |
| 57 | let mut value = Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal#::ZEROrust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]ZERO.; |
| 58 | |
| 59 | // Sum over `digits`, multiply each by its weight and add it to `value`. |
| 60 | for &digit in digits { |
| 61 | let mul = Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal#::fromrust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal][`From<i16>`]from().(10_000i16) |
| 62 | .checked_powirust-analyzer cargo rust_decimal 1.42.1 maths/impl#[Decimal][MathematicalOps]checked_powi().(weight as i64) |
| 63 | .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().("value not representable as rust_decimal::Decimal")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 64 | |
| 65 | let part = Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal#::fromrust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal][`From<i16>`]from().(digit) rust-analyzer cargo rust_decimal 1.42.1 arithmetic_impls/impl#[Decimal][`Mul<Self>`]mul().*rust-analyzer cargo rust_decimal 1.42.1 arithmetic_impls/impl#[Decimal][`Mul<Self>`]mul(). rust-analyzer cargo rust_decimal 1.42.1 arithmetic_impls/impl#[Decimal][`Mul<Self>`]mul().mul; |
| 66 | |
| 67 | value = value |
| 68 | .checked_addrust-analyzer cargo rust_decimal 1.42.1 arithmetic_impls/impl#[Decimal]checked_add().(part) |
| 69 | .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().("value not representable as rust_decimal::Decimal")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 70 | |
| 71 | weight = weight.checked_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i16]checked_sub().(1).ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().("weight underflowed")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 72 | } |
| 73 | |
| 74 | match sign { |
| 75 | PgNumericSignrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#::Positiverust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#Positive# => value.set_sign_positiverust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]set_sign_positive().(true), |
| 76 | PgNumericSignrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#::Negativerust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#Negative# => value.set_sign_negativerust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]set_sign_negative().(true), |
| 77 | } |
| 78 | |
| 79 | value.rescalerust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]rescale().(scale); |
| 80 | |
| 81 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(value) |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal#> for PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric# { |
| 86 | fn fromrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/impl#[PgNumeric][`From<Decimal>`]from().(value: Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal#) -> Selfrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/impl#[PgNumeric][`From<Decimal>`] { |
| 87 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::fromrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/impl#[PgNumeric][`From<&Decimal>`]from().(&value) |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | // This impl is effectively infallible because `NUMERIC` has a greater range than `Decimal`. |
| 92 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&'_ Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal#> for PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric# { |
| 93 | // Impl has been manually validated. |
| 94 | #[allow(clippy::cast_possible_truncation, clippy::cast_possible_wrap)] |
| 95 | fn fromrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/impl#[PgNumeric][`From<&Decimal>`]from().(decimal: &Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal#) -> Selfrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/impl#[PgNumeric][`From<&Decimal>`] { |
| 96 | if Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal#::is_zerorust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]is_zero().(decimal) { |
| 97 | return PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::ZEROrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/impl#[PgNumeric]ZERO.; |
| 98 | } |
| 99 | |
| 100 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 101 | (0u32..=28).containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]contains().(&decimal.scalerust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]scale().()), |
| 102 | "decimal scale out of range {:?}", |
| 103 | decimal.unpackrust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]unpack().(), |
| 104 | ); |
| 105 | |
| 106 | // Cannot overflow: always in the range [0, 28] |
| 107 | let scale = decimal.scalerust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]scale().() as u16; |
| 108 | |
| 109 | let mut mantissa = decimal.mantissarust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]mantissa().().unsigned_absrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i128]unsigned_abs().(); |
| 110 | |
| 111 | // If our scale is not a multiple of 4, we need to go to the next multiple. |
| 112 | let groups_diff = scale rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Rem<Self>`]rem().4; |
| 113 | if groups_diff rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt().0 { |
| 114 | let remainder = 4 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().groups_diff as u32; |
| 115 | let power = 10u32.powrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]pow().(remainder) as u128; |
| 116 | |
| 117 | // Impossible to overflow; 0 <= mantissa <= 2^96, |
| 118 | // and we're multiplying by at most 1,000 (giving us a result < 2^106) |
| 119 | mantissa rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u128][`MulAssign<Self>`]mul_assign().*=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u128][`MulAssign<Self>`]mul_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u128][`MulAssign<Self>`]mul_assign().power; |
| 120 | } |
| 121 | |
| 122 | // Array to store max mantissa of Decimal in Postgres decimal format. |
| 123 | let mut digits = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(8); |
| 124 | |
| 125 | // Convert to base-10000. |
| 126 | while mantissa rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u128][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u128][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u128][`PartialEq<Self>`]ne().0 { |
| 127 | // Cannot overflow or wrap because of the modulus |
| 128 | digits.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((mantissa rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u128][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u128][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u128][`Rem<Self>`]rem().10_000) as i16); |
| 129 | mantissa rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u128][`DivAssign<Self>`]div_assign()./=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u128][`DivAssign<Self>`]div_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u128][`DivAssign<Self>`]div_assign().10_000; |
| 130 | } |
| 131 | |
| 132 | // We started with the low digits first, but they should actually be at the end. |
| 133 | digits.reverserust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]reverse().(); |
| 134 | |
| 135 | // Cannot overflow: strictly smaller than `scale`. |
| 136 | let digits_after_decimal = scale.div_ceilrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]div_ceil().(4) as i16; |
| 137 | |
| 138 | // `mantissa` contains at most 29 decimal digits (log10(2^96)), |
| 139 | // split into at most 8 4-digit segments. |
| 140 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 141 | digits.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() <= 8, |
| 142 | "digits.len() out of range: {}; unpacked: {:?}", |
| 143 | digits.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), |
| 144 | decimal.unpackrust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]unpack().() |
| 145 | ); |
| 146 | |
| 147 | // Cannot overflow; at most 8 |
| 148 | let num_digits = digits.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() as i16; |
| 149 | |
| 150 | // Find how many 4-digit segments should go before the decimal point. |
| 151 | // `weight = 0` puts just `digit[0]` before the decimal point, and the rest after. |
| 152 | let weight = num_digits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().digits_after_decimal rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().1; |
| 153 | |
| 154 | // Remove non-significant zeroes. |
| 155 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&0) = digits.lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().() { |
| 156 | digits.poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]pop().(); |
| 157 | } |
| 158 | |
| 159 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::Numberrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number# { |
| 160 | signrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#sign.: match decimal.is_sign_negativerust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]is_sign_negative().() { |
| 161 | false => PgNumericSignrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#::Positiverust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#Positive#, |
| 162 | true => PgNumericSignrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#::Negativerust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#Negative#, |
| 163 | }, |
| 164 | // Cannot overflow; between 0 and 28 |
| 165 | scalerust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#scale.: scale as i16, |
| 166 | weightrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#weight., |
| 167 | digitsrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#digits., |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | impl Encoderust-analyzer cargo sqlx-core 0.8.3 encode/Encode#<'_, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal# { |
| 173 | fn encode_by_refrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/impl#[Decimal][`Encode<'_, Postgres>`]encode_by_ref().(&self, buf: &mut PgArgumentBufferrust-analyzer cargo sqlx-postgres 0.8.3 arguments/PgArgumentBuffer#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<IsNullrust-analyzer cargo sqlx-core 0.8.3 encode/IsNull#, BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> { |
| 174 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::fromrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/impl#[PgNumeric][`From<&Decimal>`]from().(self).encoderust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/impl#[PgNumeric]encode().(buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 175 | |
| 176 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(IsNullrust-analyzer cargo sqlx-core 0.8.3 encode/IsNull#::Norust-analyzer cargo sqlx-core 0.8.3 encode/IsNull#No#) |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | #[doc=include_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/include_str!!("rust_decimal-range.md")] |
| 181 | impl Decoderust-analyzer cargo sqlx-core 0.8.3 decode/Decode#<'_, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#> for Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal# { |
| 182 | fn decoderust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/impl#[Decimal][`Decode<'_, Postgres>`]decode().(value: PgValueRefrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueRef#<'_>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/impl#[Decimal][`Decode<'_, Postgres>`], BoxDynErrorrust-analyzer cargo sqlx-core 0.8.3 error/BoxDynError#> { |
| 183 | match value.formatrust-analyzer cargo sqlx-postgres 0.8.3 value/impl#[`PgValueRef<'r>`]format().() { |
| 184 | PgValueFormatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#::Binaryrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#Binary# => PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::decoderust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/impl#[PgNumeric]decode().(value.as_bytesrust-analyzer cargo sqlx-postgres 0.8.3 value/impl#[`PgValueRef<'r>`]as_bytes().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().(), |
| 185 | PgValueFormatrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#::Textrust-analyzer cargo sqlx-postgres 0.8.3 value/PgValueFormat#Text# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(value.as_strrust-analyzer cargo sqlx-postgres 0.8.3 value/impl#[`PgValueRef<'r>`]as_str().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal#>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().), |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | #[cfg(test)] |
| 191 | mod testsrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/tests/ { |
| 192 | use superrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/::{Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal#, PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#, PgNumericSignrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#}; |
| 193 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::convertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/::TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#; |
| 194 | |
| 195 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 196 | fn zerorust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/tests/zero().() { |
| 197 | let zero: Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal# = "0".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 198 | |
| 199 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::fromrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/impl#[PgNumeric][`From<&Decimal>`]from().(&zero), PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::ZEROrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/impl#[PgNumeric]ZERO.,); |
| 200 | |
| 201 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal#::try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/impl#[Decimal][`TryFrom<&PgNumeric>`]try_from().(&PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::ZEROrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/impl#[PgNumeric]ZERO.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal#::ZEROrust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]ZERO.); |
| 202 | } |
| 203 | |
| 204 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 205 | fn onerust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/tests/one().() { |
| 206 | let one: Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal# = "1".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 207 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 208 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryFrom<U>`]try_from().(&one).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 209 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::Numberrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number# { |
| 210 | signrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#sign.: PgNumericSignrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#::Positiverust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#Positive#, |
| 211 | scalerust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#scale.: 0, |
| 212 | weightrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#weight.: 0, |
| 213 | digitsrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#digits.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1] |
| 214 | } |
| 215 | ); |
| 216 | } |
| 217 | |
| 218 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 219 | fn tenrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/tests/ten().() { |
| 220 | let ten: Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal# = "10".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 221 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 222 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryFrom<U>`]try_from().(&ten).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 223 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::Numberrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number# { |
| 224 | signrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#sign.: PgNumericSignrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#::Positiverust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#Positive#, |
| 225 | scalerust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#scale.: 0, |
| 226 | weightrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#weight.: 0, |
| 227 | digitsrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#digits.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![10] |
| 228 | } |
| 229 | ); |
| 230 | } |
| 231 | |
| 232 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 233 | fn one_hundredrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/tests/one_hundred().() { |
| 234 | let one_hundred: Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal# = "100".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 235 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 236 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryFrom<U>`]try_from().(&one_hundred).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 237 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::Numberrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number# { |
| 238 | signrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#sign.: PgNumericSignrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#::Positiverust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#Positive#, |
| 239 | scalerust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#scale.: 0, |
| 240 | weightrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#weight.: 0, |
| 241 | digitsrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#digits.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![100] |
| 242 | } |
| 243 | ); |
| 244 | } |
| 245 | |
| 246 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 247 | fn ten_thousandrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/tests/ten_thousand().() { |
| 248 | // Decimal doesn't normalize here |
| 249 | let ten_thousand: Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal# = "10000".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 250 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 251 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryFrom<U>`]try_from().(&ten_thousand).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 252 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::Numberrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number# { |
| 253 | signrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#sign.: PgNumericSignrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#::Positiverust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#Positive#, |
| 254 | scalerust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#scale.: 0, |
| 255 | weightrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#weight.: 1, |
| 256 | digitsrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#digits.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1] |
| 257 | } |
| 258 | ); |
| 259 | } |
| 260 | |
| 261 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 262 | fn two_digitsrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/tests/two_digits().() { |
| 263 | let two_digits: Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal# = "12345".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 264 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 265 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryFrom<U>`]try_from().(&two_digits).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 266 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::Numberrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number# { |
| 267 | signrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#sign.: PgNumericSignrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#::Positiverust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#Positive#, |
| 268 | scalerust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#scale.: 0, |
| 269 | weightrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#weight.: 1, |
| 270 | digitsrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#digits.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1, 2345] |
| 271 | } |
| 272 | ); |
| 273 | } |
| 274 | |
| 275 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 276 | fn one_tenthrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/tests/one_tenth().() { |
| 277 | let one_tenth: Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal# = "0.1".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 278 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 279 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryFrom<U>`]try_from().(&one_tenth).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 280 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::Numberrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number# { |
| 281 | signrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#sign.: PgNumericSignrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#::Positiverust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#Positive#, |
| 282 | scalerust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#scale.: 1, |
| 283 | weightrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#weight.: -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().1, |
| 284 | digitsrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#digits.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1000] |
| 285 | } |
| 286 | ); |
| 287 | } |
| 288 | |
| 289 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 290 | fn decimal_1rust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/tests/decimal_1().() { |
| 291 | let decimal: Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal# = "1.2345".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 292 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 293 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryFrom<U>`]try_from().(&decimal).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 294 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::Numberrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number# { |
| 295 | signrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#sign.: PgNumericSignrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#::Positiverust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#Positive#, |
| 296 | scalerust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#scale.: 4, |
| 297 | weightrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#weight.: 0, |
| 298 | digitsrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#digits.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1, 2345] |
| 299 | } |
| 300 | ); |
| 301 | } |
| 302 | |
| 303 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 304 | fn decimal_2rust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/tests/decimal_2().() { |
| 305 | let decimal: Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal# = "0.12345".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 306 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 307 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryFrom<U>`]try_from().(&decimal).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 308 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::Numberrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number# { |
| 309 | signrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#sign.: PgNumericSignrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#::Positiverust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#Positive#, |
| 310 | scalerust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#scale.: 5, |
| 311 | weightrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#weight.: -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().1, |
| 312 | digitsrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#digits.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1234, 5000] |
| 313 | } |
| 314 | ); |
| 315 | } |
| 316 | |
| 317 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 318 | fn decimal_3rust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/tests/decimal_3().() { |
| 319 | let decimal: Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal# = "0.01234".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 320 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 321 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryFrom<U>`]try_from().(&decimal).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 322 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::Numberrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number# { |
| 323 | signrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#sign.: PgNumericSignrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#::Positiverust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#Positive#, |
| 324 | scalerust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#scale.: 5, |
| 325 | weightrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#weight.: -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().1, |
| 326 | digitsrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#digits.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0123, 4000] |
| 327 | } |
| 328 | ); |
| 329 | } |
| 330 | |
| 331 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 332 | fn decimal_4rust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/tests/decimal_4().() { |
| 333 | let decimal: Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal# = "12345.67890".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 334 | let expected_numeric = PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::Numberrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number# { |
| 335 | signrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#sign.: PgNumericSignrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#::Positiverust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#Positive#, |
| 336 | scalerust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#scale.: 5, |
| 337 | weightrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#weight.: 1, |
| 338 | digitsrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#digits.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1, 2345, 6789], |
| 339 | }; |
| 340 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryFrom<U>`]try_from().(&decimal).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), expected_numeric); |
| 341 | |
| 342 | let actual_decimal = Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal#::try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/impl#[Decimal][`TryFrom<PgNumeric>`]try_from().(expected_numeric).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 343 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(actual_decimal, decimal); |
| 344 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(actual_decimal.mantissarust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]mantissa().(), 1234567890); |
| 345 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(actual_decimal.scalerust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]scale().(), 5); |
| 346 | } |
| 347 | |
| 348 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 349 | fn one_digit_decimalrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/tests/one_digit_decimal().() { |
| 350 | let one_digit_decimal: Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal# = "0.00001234".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 351 | let expected_numeric = PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::Numberrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number# { |
| 352 | signrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#sign.: PgNumericSignrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#::Positiverust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#Positive#, |
| 353 | scalerust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#scale.: 8, |
| 354 | weightrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#weight.: -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().2, |
| 355 | digitsrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#digits.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1234], |
| 356 | }; |
| 357 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 358 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryFrom<U>`]try_from().(&one_digit_decimal).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 359 | expected_numeric |
| 360 | ); |
| 361 | |
| 362 | let actual_decimal = Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal#::try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/impl#[Decimal][`TryFrom<PgNumeric>`]try_from().(expected_numeric).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 363 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(actual_decimal, one_digit_decimal); |
| 364 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(actual_decimal.mantissarust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]mantissa().(), 1234); |
| 365 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(actual_decimal.scalerust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]scale().(), 8); |
| 366 | } |
| 367 | |
| 368 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 369 | fn max_valuerust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/tests/max_value().() { |
| 370 | let expected_numeric = PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::Numberrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number# { |
| 371 | signrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#sign.: PgNumericSignrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#::Positiverust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#Positive#, |
| 372 | scalerust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#scale.: 0, |
| 373 | weightrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#weight.: 7, |
| 374 | digitsrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#digits.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![7, 9228, 1625, 1426, 4337, 5935, 4395, 0335], |
| 375 | }; |
| 376 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 377 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryFrom<U>`]try_from().(&Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal#::MAXrust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]MAX.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 378 | expected_numeric |
| 379 | ); |
| 380 | |
| 381 | let actual_decimal = Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal#::try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/impl#[Decimal][`TryFrom<PgNumeric>`]try_from().(expected_numeric).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 382 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(actual_decimal, Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal#::MAXrust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]MAX.); |
| 383 | // Value split by 10,000's to match the expected digits[] |
| 384 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 385 | actual_decimal.mantissarust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]mantissa().(), |
| 386 | 7_9228_1625_1426_4337_5935_4395_0335 |
| 387 | ); |
| 388 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(actual_decimal.scalerust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]scale().(), 0); |
| 389 | } |
| 390 | |
| 391 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 392 | fn max_value_max_scalerust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/tests/max_value_max_scale().() { |
| 393 | let mut max_value_max_scale = Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal#::MAXrust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]MAX.; |
| 394 | max_value_max_scale.set_scalerust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]set_scale().(28).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 395 | |
| 396 | let expected_numeric = PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::Numberrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number# { |
| 397 | signrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#sign.: PgNumericSignrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#::Positiverust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#Positive#, |
| 398 | scalerust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#scale.: 28, |
| 399 | weightrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#weight.: 0, |
| 400 | digitsrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#digits.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![7, 9228, 1625, 1426, 4337, 5935, 4395, 0335], |
| 401 | }; |
| 402 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 403 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryFrom<U>`]try_from().(&max_value_max_scale).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 404 | expected_numeric |
| 405 | ); |
| 406 | |
| 407 | let actual_decimal = Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal#::try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/impl#[Decimal][`TryFrom<PgNumeric>`]try_from().(expected_numeric).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 408 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(actual_decimal, max_value_max_scale); |
| 409 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 410 | actual_decimal.mantissarust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]mantissa().(), |
| 411 | 79_228_162_514_264_337_593_543_950_335 |
| 412 | ); |
| 413 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(actual_decimal.scalerust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]scale().(), 28); |
| 414 | } |
| 415 | |
| 416 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 417 | fn issue_423_four_digitrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/tests/issue_423_four_digit().() { |
| 418 | // This is a regression test for https://github.com/launchbadge/sqlx/issues/423 |
| 419 | let four_digit: Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal# = "1234".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 420 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 421 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryFrom<U>`]try_from().(&four_digit).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 422 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::Numberrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number# { |
| 423 | signrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#sign.: PgNumericSignrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#::Positiverust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#Positive#, |
| 424 | scalerust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#scale.: 0, |
| 425 | weightrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#weight.: 0, |
| 426 | digitsrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#digits.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1234] |
| 427 | } |
| 428 | ); |
| 429 | } |
| 430 | |
| 431 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 432 | fn issue_423_negative_four_digitrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/tests/issue_423_negative_four_digit().() { |
| 433 | // This is a regression test for https://github.com/launchbadge/sqlx/issues/423 |
| 434 | let negative_four_digit: Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal# = "-1234".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 435 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 436 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryFrom<U>`]try_from().(&negative_four_digit).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 437 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::Numberrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number# { |
| 438 | signrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#sign.: PgNumericSignrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#::Negativerust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#Negative#, |
| 439 | scalerust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#scale.: 0, |
| 440 | weightrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#weight.: 0, |
| 441 | digitsrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#digits.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1234] |
| 442 | } |
| 443 | ); |
| 444 | } |
| 445 | |
| 446 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 447 | fn issue_423_eight_digitrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/tests/issue_423_eight_digit().() { |
| 448 | // This is a regression test for https://github.com/launchbadge/sqlx/issues/423 |
| 449 | let eight_digit: Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal# = "12345678".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 450 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 451 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryFrom<U>`]try_from().(&eight_digit).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 452 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::Numberrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number# { |
| 453 | signrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#sign.: PgNumericSignrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#::Positiverust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#Positive#, |
| 454 | scalerust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#scale.: 0, |
| 455 | weightrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#weight.: 1, |
| 456 | digitsrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#digits.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1234, 5678] |
| 457 | } |
| 458 | ); |
| 459 | } |
| 460 | |
| 461 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 462 | fn issue_423_negative_eight_digitrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/tests/issue_423_negative_eight_digit().() { |
| 463 | // This is a regression test for https://github.com/launchbadge/sqlx/issues/423 |
| 464 | let negative_eight_digit: Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal# = "-12345678".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 465 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 466 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryFrom<U>`]try_from().(&negative_eight_digit).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 467 | PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::Numberrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number# { |
| 468 | signrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#sign.: PgNumericSignrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#::Negativerust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#Negative#, |
| 469 | scalerust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#scale.: 0, |
| 470 | weightrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#weight.: 1, |
| 471 | digitsrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#digits.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1234, 5678] |
| 472 | } |
| 473 | ); |
| 474 | } |
| 475 | |
| 476 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 477 | fn issue_2247_trailing_zerosrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/tests/issue_2247_trailing_zeros().() { |
| 478 | // This is a regression test for https://github.com/launchbadge/sqlx/issues/2247 |
| 479 | let one_hundred: Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal# = "100.00".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 480 | let expected_numeric = PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::Numberrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number# { |
| 481 | signrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#sign.: PgNumericSignrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#::Positiverust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumericSign#Positive#, |
| 482 | scalerust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#scale.: 2, |
| 483 | weightrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#weight.: 0, |
| 484 | digitsrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#Number#digits.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![100], |
| 485 | }; |
| 486 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(PgNumericrust-analyzer cargo sqlx-postgres 0.8.3 types/numeric/PgNumeric#::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryFrom<U>`]try_from().(&one_hundred).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), expected_numeric); |
| 487 | |
| 488 | let actual_decimal = Decimalrust-analyzer cargo rust_decimal 1.42.1 decimal/Decimal#::try_fromrust-analyzer cargo sqlx-postgres 0.8.3 types/rust_decimal/impl#[Decimal][`TryFrom<PgNumeric>`]try_from().(expected_numeric).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 489 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(actual_decimal, one_hundred); |
| 490 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(actual_decimal.mantissarust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]mantissa().(), 10000); |
| 491 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(actual_decimal.scalerust-analyzer cargo rust_decimal 1.42.1 decimal/impl#[Decimal]scale().(), 2); |
| 492 | } |
| 493 | } |