pub enum DecimalView<'a> {
String {
value: &'a str,
},
Scaled {
scale: u8,
value: Cow<'a, [u8]>,
},
}Expand description
A decimal value backed by either a string representation or a scaled mantissa.
Decimal values can be serialized in two formats:
§Text Format
The decimal is written as a string representation followed by a 'd' suffix.
Example: "123.45d" or "1.5e-3d"
§Binary Format
A more compact binary encoding consisting of:
- Binary format marker:
'='(0x3D) - Type identifier:
DECIMAL_BINARY_FORMAT_TYPEbyte - Scale: 1 byte (0-76 inclusive) - number of decimal places
- Length: 1 byte - number of bytes in the unscaled value
- Unscaled value: variable-length byte array in two’s complement format, big-endian
Example: For decimal 123.45 with scale 2:
Unscaled value: 12345
Binary representation:
= [23] [2] [2] [0x30] [0x39]
│ │ │ │ └───────────┘
│ │ │ │ └─ Mantissa bytes (12345 in big-endian)
│ │ │ └─ Length: 2 bytes
│ │ └─ Scale: 2
│ └─ Type: DECIMAL_BINARY_FORMAT_TYPE (23)
└─ Binary marker: '='§Binary Format Notes
- The unscaled value must be encoded in two’s complement big-endian format
- Maximum scale is 76
- Length byte indicates how many bytes follow for the unscaled value
Variants§
Implementations§
Source§impl<'a> DecimalView<'a>
impl<'a> DecimalView<'a>
Sourcepub fn try_new_scaled<T>(scale: u32, value: T) -> Result<Self>
pub fn try_new_scaled<T>(scale: u32, value: T) -> Result<Self>
Creates a DecimalView::Scaled from a mantissa buffer and scale.
Validates that:
scaledoes not exceed the QuestDB maximum of 76 decimal places.- The mantissa fits into at most 32 bytes (ILP binary limit).
Returns an error::ErrorCode::InvalidDecimal
error if either constraint is violated.
Sourcepub fn try_new_string(value: &'a str) -> Result<Self>
pub fn try_new_string(value: &'a str) -> Result<Self>
Creates a DecimalView::String from a textual decimal representation.
Thousand separators (commas) are not allowed and the decimal point must be a dot (.).
Performs lightweight validation and rejects values containing ILP-reserved characters.
Accepts plain decimals, optional +/- prefixes, NaN, Infinity, and scientific
notation (e/E).
Returns error::ErrorCode::InvalidDecimal
if disallowed characters are encountered.
Trait Implementations§
Source§impl<'a> Debug for DecimalView<'a>
impl<'a> Debug for DecimalView<'a>
Source§impl<'a> TryInto<DecimalView<'a>> for &'a BigDecimal
Available on crate feature bigdecimal only.
impl<'a> TryInto<DecimalView<'a>> for &'a BigDecimal
bigdecimal only.Source§impl<'a> TryInto<DecimalView<'a>> for &'a Decimal
Available on crate feature rust_decimal only.
impl<'a> TryInto<DecimalView<'a>> for &'a Decimal
rust_decimal only.Source§impl<'a> TryInto<DecimalView<'a>> for &'a str
Implementation for string slices containing decimal representations.
impl<'a> TryInto<DecimalView<'a>> for &'a str
Implementation for string slices containing decimal representations.
This implementation uses the text format.
§Format
The string is validated and written as-is, followed by the ‘d’ suffix. Thousand separators
(commas) are not allowed and the decimal point must be a dot (.).
§Validation
The implementation performs partial validation only:
- Rejects non-numerical characters (not -/+, 0-9, ., Infinity, NaN, e/E)
- Does NOT validate the actual decimal syntax (e.g., “e2e” would pass)
This is intentional: full parsing would add overhead. The QuestDB server performs complete validation and will reject malformed decimals.
§Examples
"123.45"→"123.45d""1.5e-3"→"1.5e-3d""-0.001"→"-0.001d"
§Errors
Returns [Error] with ErrorCode::InvalidDecimal
if the string contains non-numerical characters.