DecimalView

Enum DecimalView 

Source
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:

  1. Binary format marker: '=' (0x3D)
  2. Type identifier: DECIMAL_BINARY_FORMAT_TYPE byte
  3. Scale: 1 byte (0-76 inclusive) - number of decimal places
  4. Length: 1 byte - number of bytes in the unscaled value
  5. 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§

§

String

Fields

§value: &'a str
§

Scaled

Fields

§scale: u8
§value: Cow<'a, [u8]>

Implementations§

Source§

impl<'a> DecimalView<'a>

Source

pub fn try_new_scaled<T>(scale: u32, value: T) -> Result<Self>
where T: Into<Cow<'a, [u8]>>,

Creates a DecimalView::Scaled from a mantissa buffer and scale.

Validates that:

  • scale does 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.

Source

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>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> TryInto<DecimalView<'a>> for &'a BigDecimal

Available on crate feature bigdecimal only.
Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<DecimalView<'a>>

Performs the conversion.
Source§

impl<'a> TryInto<DecimalView<'a>> for &'a Decimal

Available on crate feature rust_decimal only.
Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<DecimalView<'a>>

Performs the conversion.
Source§

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.

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<DecimalView<'a>>

Performs the conversion.

Auto Trait Implementations§

§

impl<'a> Freeze for DecimalView<'a>

§

impl<'a> RefUnwindSafe for DecimalView<'a>

§

impl<'a> Send for DecimalView<'a>

§

impl<'a> Sync for DecimalView<'a>

§

impl<'a> Unpin for DecimalView<'a>

§

impl<'a> UnwindSafe for DecimalView<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V