-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
Is your feature request related to a problem or challenge? Please describe what you are trying to do.
This is actually a question or a discussion.
Our current may to implement Decimal128 and Decimal256 is:
trait BasicDecimal: ... {
const BIT_LENGTH: i32;
}
struct Decimal128 {}
struct Decimal256 {}
impl BasicDecimal for Decimal128 {}
impl BasicDecimal for Decimla256{}
impl Decimal128 {}Actually I find an alternative way to implement this:
struct Decimal<const BYTE_LENGTH: usize> {
precision: usize,
scale: usize,
value: [u8; BYTE_LENGTH],
}
impl<BYTE_LENGTH> Decimal<BYTE_LENGTH> {}
type Decimal128 = Decimal<16>;
type Decimal256 = Decimal<32>;
impl Decimal128 {}I am not sure which one is better, but these are some pros and cons I thought:
pros: don't need the basic trait, reducing using macro when coding (better debugging)
cons: cannot restrict the bit_length to be 128 or 256 because const_generic_exprs is an unstable feature.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels