Skip to main content

Value

Enum Value 

Source
#[non_exhaustive]
pub enum Value<'a> { Str(&'a str), Int(i64), Float(f64), Decimal(&'a str), Number(Number), Custom(&'a dyn CustomValue), Boxed(Box<dyn Any>), Fallback(FallbackSource<'a>), DateTime(DateTime<'a>), Measure(Measure<'a>), }
Expand description

A resolved value’s data. The handler that resolved it decides how it formats and selects; a value no handler resolved (a literal, an argument) is unannotated (plans/03-runtime.md §2.6).

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Str(&'a str)

A string: a literal, a string argument, or :string’s operand.

§

Int(i64)

An integer argument.

§

Float(f64)

A float argument.

§

Decimal(&'a str)

A decimal argument (number-literal text).

§

Number(Number)

A number and its resolved options: :number, :integer, :offset, :percent.

§

Custom(&'a dyn CustomValue)

An application value.

§

Boxed(Box<dyn Any>)

A custom handler’s own data (the only allocation a handler makes).

§

Fallback(FallbackSource<'a>)

A fallback value, as a function’s operand: the operand failed to resolve (an unresolved variable, a declaration that failed). The handler decides — the numeric ones report Bad Operand, :string takes the text of its representation ({$x}), as the suite expects (plans/03-runtime.md §2.6).

§

DateTime(DateTime<'a>)

A date/time: an argument, or what :datetime, :date, :time resolved (with its options).

§

Measure(Measure<'a>)

A number with a currency or a unit: what :currency and :unit resolved.

Implementations§

Source§

impl<'a> Value<'a>

Source

pub fn from_arg(arg: Arg<'a>) -> Option<Value<'a>>

The value of an argument; None for Arg::Unset.

Source

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

Its string form when it has one without formatting: a string, a decimal’s text, or an application value’s as_str.

Source

pub fn to_number(&self, host: &dyn Host) -> Option<Number>

Its numeric value under the numeric-operand rules (number.md, “Numeric Operands”): a string or decimal matching number-literal, an integer, a finite float, a number or a measure (its value, without options), an application value’s as_number (else its measure’s).

Source

pub fn digit_size(&self) -> Option<u8>

Its value as a digit size option (number.md): an integer 0–99 — an integer, an integral float, a number, or a string of one or two digits without a leading zero. For the function crates’ own options of that type (fractionDigits).

Source

pub fn downcast_ref<T: Any>(&self) -> Option<&T>

The concrete value, when it is a T: a Value::Boxed, or an application value whose as_any gives one.

Trait Implementations§

Source§

impl Debug for Value<'_>

As a derived Debug would show it, but an application value and a handler’s own data, which have no Debug of their own, are Custom(..) and Boxed(..).

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !Freeze for Value<'a>

§

impl<'a> !RefUnwindSafe for Value<'a>

§

impl<'a> !Send for Value<'a>

§

impl<'a> !Sync for Value<'a>

§

impl<'a> !UnwindSafe for Value<'a>

§

impl<'a> Unpin for Value<'a>

§

impl<'a> UnsafeUnpin for Value<'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 = !

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

fn try_from(value: U) -> Result<T, !>

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.