rust-decimal
rust-decimal copied to clipboard
Plans for const generics?
I've been loving this crate so far. Seeing as min_const_generics
is on track for rust 1.51, is there plans for using const generics within this crate? I find that being able to constrain the scale directly in my struct definitions would be a great use-case.
While I haven't got any surefire plans to add min_const_generics
just yet, I do plan to investigate where I can leverage the feature once it's released. Happy for suggestions if you have a specific area you'd like to target?
So you know, I've been doing the same with const_fn
: I've been adding it where it makes sense, but also trying to be smart about where it gets added. At some stage I'd love to do a full library review to see where else I can make improvements, though admittedly am waiting until after I cover some of the add/mul improvements I have lined up.
Personally I'd love to do like in postgres where you set the precision and the scale statically
CREATE TABLE some_table (
my_data_point DECIMAL(11, 8) NOT NULL
);
And to be able to do this equivalent in my structs
struct SomeTable {
my_data_point: Decimal<11, 8>,
}
Where the 8 would represent the scale used when creating a new Decimal. How ever im not really sure where the precision would fit inside the implementation. In which case even just setting the scale can be nice
struct SomeTable {
my_data_point: Decimal<8>
}
Of course this would break the current API. So maybe something more along the lines of DecimalScale<const N: u32>
or to opt into it with a feature flag or something.