pub struct Numeric(/* private fields */);Expand description
A fixed-scale decimal (Numeric), stored as its decimal string — the wire
representation (Daml numerics are transmitted as text to avoid binary-float
rounding).
Comparison is numeric, not textual: the ledger echoes values at the
type’s full scale (submit "1.5" on a Numeric 10, read back
"1.5000000000"), so ==/Ord/Hash compare the canonical decimal value
— Numeric("1.5") == Numeric("1.5000000000"). A string that does not parse
as a decimal falls back to plain string comparison (and never equals a
valid decimal).
LF-JSON: emitted as a string (what the Ledger API produces); on input
also accepts a JSON number (the spec allows it — high-precision values
should still use the string form, since a JSON number literal is already
f64-lossy on the wire).
Validation is asymmetric on purpose. Numeric::parse / str::parse
reject anything that is not a decimal literal, so a caller’s typo fails at
construction. Values arriving from the ledger — deserialization and the gRPC
codec — are taken as-is via Numeric::from_wire: the participant is the
authority on the format, and rejecting an unfamiliar-but-harmless spelling
would break decoding of a payload the ledger considers valid. A value that
is not a decimal literal simply falls out of canonical comparison and never
equals a valid one.
Implementations§
Source§impl Numeric
impl Numeric
Sourcepub fn parse(text: impl Into<String>) -> Result<Self, NumericParseError>
pub fn parse(text: impl Into<String>) -> Result<Self, NumericParseError>
Parse a decimal string (-?digits[.digits]; a leading + is accepted),
rejecting anything the ledger would reject — use this over raw
construction so a typo fails here instead of at command submission.
§Errors
Returns NumericParseError when the input is not a decimal literal.
Sourcepub fn from_wire(text: impl Into<String>) -> Self
pub fn from_wire(text: impl Into<String>) -> Self
Wrap a decimal string without validating it — for values that came
off the wire, where the ledger has already vouched for the format.
Prefer Numeric::parse for values a caller typed.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Numeric
impl<'de> Deserialize<'de> for Numeric
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
impl Eq for Numeric
Source§impl FromValue for Numeric
impl FromValue for Numeric
Source§fn from_value(value: &Value) -> Result<Self, ValueError>
fn from_value(value: &Value) -> Result<Self, ValueError>
Source§impl Ord for Numeric
impl Ord for Numeric
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Numeric
impl PartialOrd for Numeric
Auto Trait Implementations§
impl Freeze for Numeric
impl RefUnwindSafe for Numeric
impl Send for Numeric
impl Sync for Numeric
impl Unpin for Numeric
impl UnsafeUnpin for Numeric
impl UnwindSafe for Numeric
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request