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.
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.
Implementations§
Source§impl OracleNumber
impl OracleNumber
Sourcepub fn coefficient(&self) -> Option<i128>
pub fn coefficient(&self) -> Option<i128>
The inline coefficient as an i128, or None for the boxed-text
fallback. value == coefficient × 10^-scale.
Sourcepub fn from_wire(bytes: &[u8]) -> Result<Self>
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.
Sourcepub fn from_canonical_text(text: &str) -> Self
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). Integral trailing-zero values are folded into the same
coefficient/negative-scale form the wire decoder emits.
Sourcepub fn from_canonical_text_with_flag(text: &str, is_integer: bool) -> Self
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).
Sourcepub fn as_borrowed_text(&self) -> Option<&str>
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.
Sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Whether the canonical text is integral (carries no decimal point).
Mirrors the legacy is_integer flag exactly.
Sourcepub fn fmt_into(&self, out: &mut String)
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.
Sourcepub fn to_canonical_string(&self) -> String
pub fn to_canonical_string(&self) -> String
Canonical decimal text as an owned String.
Sourcepub fn to_canonical_cow(&self) -> Cow<'_, str>
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).
Trait Implementations§
Source§impl Clone for OracleNumber
impl Clone for OracleNumber
Source§fn clone(&self) -> OracleNumber
fn clone(&self) -> OracleNumber
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for OracleNumber
impl Debug for OracleNumber
Source§impl Display for OracleNumber
impl Display for OracleNumber
impl Eq for OracleNumber
Source§impl PartialEq for OracleNumber
impl PartialEq for OracleNumber
Source§fn eq(&self, other: &OracleNumber) -> bool
fn eq(&self, other: &OracleNumber) -> bool
self and other values to be equal, and is used by ==.