|
1 | 1 | use bigdecimal::BigDecimal; |
| 2 | +use crate::error::AppError; |
| 3 | +use crate::serde::decode::Decode; |
2 | 4 |
|
3 | 5 | use crate::serde::encode::{Encode, Encoded}; |
4 | 6 |
|
5 | 7 | #[derive(Hash, Eq, PartialEq)] |
6 | 8 | pub struct Decimal128(BigDecimal); |
7 | 9 |
|
| 10 | + |
| 11 | +/** |
| 12 | +f128 implemented in |
| 13 | +https://github.com/rust-lang/rfcs/pull/3453 |
| 14 | +implement this when it is available in stable. |
| 15 | +*/ |
8 | 16 | impl Encode for Decimal128 { |
9 | 17 | fn encode(&self) -> Encoded { |
10 | 18 | 0x94.into() |
11 | 19 | } |
12 | 20 | } |
13 | 21 |
|
14 | | -impl From<f64> for Decimal128 { |
15 | | - fn from(value: f64) -> Self { |
16 | | - Decimal128(BigDecimal::try_from(value).unwrap()) |
| 22 | +impl Decode for Decimal128 { |
| 23 | + fn can_decode(_iter: impl Iterator<Item=u8>) -> bool { |
| 24 | + false // Not implemented yet |
17 | 25 | } |
18 | | -} |
19 | 26 |
|
20 | | -#[derive(thiserror::Error, Debug)] |
21 | | -pub enum Decimal128ConversionError { |
22 | | - #[error("Coefficient is too large for Decimal128 representation.")] |
23 | | - CoefficientTooLarge, |
24 | | - #[error("Exponent overflowed in Decimal128 representation")] |
25 | | - ExponentOverflow, |
26 | | - #[error("Exponent underflowed in Decimal128 representation")] |
27 | | - ExponentUnderflow, |
| 27 | + fn try_decode(_iter: impl Iterator<Item=u8>) -> Result<Self, AppError> where Self: Sized { |
| 28 | + todo!("Decimal128 type is not implemented yet") |
| 29 | + } |
28 | 30 | } |
29 | 31 |
|
30 | 32 | #[cfg(test)] |
31 | 33 | mod test { |
32 | | - use super::*; |
33 | | - |
34 | | - #[test] |
35 | | - fn construct_decimal_128() { |
36 | | - let val: Decimal128 = 128.0.into(); |
37 | | - assert_eq!(val.encode().constructor(), 0x94); |
38 | | - } |
39 | 34 | } |
0 commit comments