-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
It's hard to pass around the content of tuple/struct enum variants with multiple members -- you have to unpack them and pass scalar values around, which is bulky and error-prone (**). Should we consider creating a struct or family of structs for representing scalar decimal values?
(**)
It would be lovely if Variant::Decimal4 were an actual type in rust. It actually is a type under the hood, but the language doesn't expose it as such, because the enum discriminant has to be stored somewhere and rust usually embeds it in the variant itself to save space. See https://rust-lang.github.io/rfcs/2195-really-tagged-unions.html#guide-level-explanation for gory details.
Originally posted by @scovich in #7644 (comment)
I believe the high level proposal is something like
Instead of
enum Variant {
...
Decimal4 { integer: i32, scale: u8 },
Decimal8 { integer: i64, scale: u8 },
Decimal16 { integer: i128, scale: u8 },
...
}struct Decimal4Value
{
integer: i32, scale: u8
};
enum Variant {
...
Decimal4(Decimal4Value)
...
}And likewise for Decimal8 , Decimal16, etc