Skip to main content

OracleNumber

Enum OracleNumber 

Source
pub enum OracleNumber {
    Inline {
        coefficient_le: [u8; 16],
        scale: i16,
        is_integer: bool,
    },
    Text {
        text: Box<str>,
        is_integer: bool,
    },
}
Expand description

Inline, lossless decimal carrier for an Oracle NUMBER.

The common case is OracleNumber::Inline (coefficient × 10^-scale, allocation-free). Values that cannot be represented exactly inline fall back to OracleNumber::Text (a boxed canonical-text carrier).

Variants§

§

Inline

value == coefficient × 10^-scale, with the sign carried in coefficient. scale may be negative (the value has trailing zeros to the left of the implied point). is_integer mirrors the legacy decoder’s flag — whether the canonical text contains a decimal point — so the Python int-vs-float dispatch is preserved exactly.

The coefficient is stored as its little-endian i128 bytes rather than a bare i128 field: a bare i128 forces 16-byte alignment, which rounds the enum up to 32 bytes and would blow QueryValue’s 32-byte budget once the discriminant is added. The [u8; 16] form keeps 8-byte alignment so OracleNumber is 24 bytes. Access via OracleNumber::coefficient.

Fields

§coefficient_le: [u8; 16]
§scale: i16
§is_integer: bool
§

Text

Defensive fallback for values that do not fit the inline form exactly (39–40 significant digit integers that overflow i128, or the -1e126 single-byte sentinel). Boxed so the enum stays small.

Fields

§text: Box<str>
§is_integer: bool

Implementations§

Source§

impl OracleNumber

Source

pub fn coefficient(&self) -> Option<i128>

The inline coefficient as an i128, or None for the boxed-text fallback. value == coefficient × 10^-scale.

Source

pub fn scale(&self) -> Option<i16>

The inline scale, or None for the boxed-text fallback.

Source

pub fn from_wire(bytes: &[u8]) -> Result<Self>

Decode an Oracle NUMBER wire form into the inline representation, falling back to a boxed canonical-text carrier when the value cannot be represented exactly inline. The canonical text — whether produced inline or stored in the fallback — is byte-identical to the legacy decoder.

ZERO-ALLOCATION for the common inline case: the digit walk writes into a fixed stack buffer (Oracle NUMBER has at most 40 significant digits), and the inline coefficient/scale is folded directly — no scratch Vec/String is heap-allocated. Only the rare text fallback (sentinel / i128 overflow) touches the heap, and only then.

Source

pub fn from_canonical_text(text: &str) -> Self

Construct from already-canonical decimal text (the bind / parse path). Parses the text into the inline form when it fits, else keeps it boxed. The text MUST already be canonical Oracle NUMBER text (the form the decoder emits); this does not re-canonicalize.

Source

pub fn from_canonical_text_with_flag(text: &str, is_integer: bool) -> Self

Like Self::from_canonical_text but with the caller-supplied is_integer flag (the borrowed fetch path already decoded it from the wire, so it is authoritative — preserve it verbatim).

Source

pub fn as_borrowed_text(&self) -> Option<&str>

Borrow the canonical text when it is stored as boxed text (the fallback form), else None — the inline numeric form synthesizes its text on demand and has no &str to lend.

Source

pub fn is_integer(&self) -> bool

Whether the canonical text is integral (carries no decimal point). Mirrors the legacy is_integer flag exactly.

Source

pub fn fmt_into(&self, out: &mut String)

THE single shared canonical formatter. Appends the canonical decimal text to out. Byte-identical to super::codecs::decode_number_text_into.

Source

pub fn to_canonical_string(&self) -> String

Canonical decimal text as an owned String.

Source

pub fn to_canonical_cow(&self) -> Cow<'_, str>

Canonical decimal text as a Cow: borrowed for the boxed-text fallback (zero allocation), owned for the inline form (formatted once on demand).

Source

pub fn to_i64(&self) -> Option<i64>

Exact i64 when the value is an integer that fits; else None.

Source

pub fn to_i128(&self) -> Option<i128>

Exact i128 when the value is an integer that fits; else None.

Trait Implementations§

Source§

impl Clone for OracleNumber

Source§

fn clone(&self) -> OracleNumber

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OracleNumber

Source§

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

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

impl Display for OracleNumber

Source§

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

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

impl Eq for OracleNumber

Source§

impl PartialEq for OracleNumber

Source§

fn eq(&self, other: &OracleNumber) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for OracleNumber

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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