Skip to main content

Value

Struct Value 

Source
pub struct Value {
    pub pos: Pos,
    pub kind: ValueKind,
}
Expand description

A data value.

Fields§

§pos: Pos

The position of the start of the value.

§kind: ValueKind

What the value is.

Implementations§

Source§

impl Value

Source

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

The name of a tagged value, as it is written, such as Follow for Follow or Preferences for Preferences { ... }, whatever follows the name. A name that starts with a lower-case letter or _, such as true, is a reference to a const, which is not resolved. None for any other kind of value.

Source

pub fn members(&self) -> Option<&[Member]>

The members of a record, either untagged, as in { x: 1 }, or after a tag, as in Move { x: 1 }. None for any other kind of value.

Source

pub fn field(&self, name: &str) -> Option<&Value>

The value of the member called name of a record, as for members. None if the value is not a record or has no such member. A duplicate member is not an error here: the first is found.

Source

pub fn require_field(&self, name: &str) -> Result<&Value, Error>

The value of the member called name of a record, as for field, or an error at this value that says why there is none, in the words of check: Missing field layout in Preferences, or for a value that is not a record, Expected a record but found Nat. A duplicate member is not an error here: the first is found.

Source

pub fn as_str(&self) -> Result<&str, Error>

The text of a string.

Source

pub fn as_array(&self) -> Result<&[Value], Error>

The elements of an array, either untagged, as in [1, 2], or after a tag, as in Users[u1, u2].

Source

pub fn as_bool(&self) -> Result<bool, Error>

A Bool of the prelude: True or False, or true or false, which are the prelude’s consts for them, or the full names constructo.prelude::True and constructo.prelude::False, which a codec writes with Names::Full. These names are known here, although the syntax knows no types, because a Bool is too common for every reader to work this out again. They are accepted even when the prelude is not loaded.

Source

pub fn as_u64(&self) -> Result<u64, Error>

A Nat, as a u64. A number that is too large is an error at it.

Source

pub fn as_i64(&self) -> Result<i64, Error>

An Int, or a Nat widened to one, as an i64. A number that is too large is an error at it.

Source

pub fn as_f64(&self) -> Result<f64, Error>

A Float, or a Nat or an Int widened to one, as the nearest f64. A number too large for an f64 is an error at it.

Source

pub fn names<'a>(&'a self, out: &mut Vec<(&'a str, Pos)>)

Collects the names that the value uses on their own or as the tag of a body, with their positions. Any of them may refer to a const, which is for the caller to decide.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Self

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 Value

Source§

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

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

impl Eq for Value

Source§

impl PartialEq for Value

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Value

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> 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 = !

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.