Skip to main content

Numeric

Enum Numeric 

Source
pub enum Numeric {
    Integer(i64),
    Decimal(Decimal),
    Double(f64),
    Float(f64),
}
Expand description

XPath 2.0 numeric type discriminator carried by Value::Number.

XML Schema / F&O distinguishes four numeric primitives — xs:integer, xs:decimal, xs:double, xs:float — and the distinction is observable: instance of must tell an integer from a double, and the number→string rule (F&O §17.1.2) stringifies doubles/floats in scientific notation but integers/decimals in decimal form. Tracking the kind on the value itself lets those operators answer correctly without a second type carrier.

Decimal is exact (backed by rust_decimal::Decimal — 96-bit mantissa + scale, ≥28 significant digits), so XPath 2.0’s 0.1 + 0.2 is 0.3, not 0.30000000000000004 (XPath 2.0 §3.1.1 types a literal containing . as xs:decimal, and the spec demands exact arithmetic on it). Double/Float stay f64-backed. All four payloads are inline and Copy, so Value::Number stays a cheap non-allocating variant — a positional predicate’s literal 2 is Numeric::Integer(2) with no heap cost.

Variants§

§

Integer(i64)

§

Decimal(Decimal)

§

Double(f64)

§

Float(f64)

Implementations§

Source§

impl Numeric

Source

pub fn as_f64(self) -> f64

The numeric value as an f64 — the universal accessor every XPath 1.0-style consumer reads, regardless of the underlying numeric type. Integer(i) widens to i as f64; Decimal(d) projects via rust_decimal::prelude::ToPrimitive (the lossy step — values past 2^53 lose precision, values beyond f64 range collapse to f64::NAN).

Source

pub fn integer_from_f64(n: f64) -> Numeric

Build an xs:integer from an f64. i64-backed (no arbitrary precision): a result outside i64 range falls back to an xs:decimal so the magnitude survives — saturation at i64::MAX would pin a growing value and hang recursive big-integer arithmetic. Non-finite values stay as Double (NaN / ±∞ have no decimal representation per XSD §3.2.3).

Source

pub fn of_kind(kind: &str, n: f64) -> Numeric

Build a Numeric of the given XSD primitive kind from an f64 — used by arithmetic promotion to tag a result with its promoted type. An unrecognised kind falls back to Double. Note: this conversion goes through f64, so decimal arithmetic that needs to stay exact must NOT route through here — see [Numeric::decimal_op] for the exact path.

Source

pub fn kind(self) -> &'static str

XSD primitive type local name ("integer", "decimal", "double", "float") — the discriminator instance of and the stringification rule branch on.

Trait Implementations§

Source§

impl Clone for Numeric

Source§

fn clone(&self) -> Numeric

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 Copy for Numeric

Source§

impl Debug for Numeric

Source§

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

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

impl From<f64> for Numeric

Source§

fn from(n: f64) -> Numeric

A bare f64 with no further type information defaults to xs:double — the XPath 1.0 numeric type and the F&O default for an untyped numeric.

Source§

impl PartialEq for Numeric

Source§

fn eq(&self, other: &Numeric) -> 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 Numeric

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<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> 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, 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.