pub struct Value {
pub pos: Pos,
pub kind: ValueKind,
}Expand description
A data value.
Fields§
§pos: PosThe position of the start of the value.
kind: ValueKindWhat the value is.
Implementations§
Source§impl Value
impl Value
Sourcepub fn tag(&self) -> Option<&str>
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.
Sourcepub fn members(&self) -> Option<&[Member]>
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.
Sourcepub fn field(&self, name: &str) -> Option<&Value>
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.
Sourcepub fn require_field(&self, name: &str) -> Result<&Value, Error>
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.
Sourcepub fn as_array(&self) -> Result<&[Value], Error>
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].
Sourcepub fn as_bool(&self) -> Result<bool, Error>
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.
Sourcepub fn as_u64(&self) -> Result<u64, Error>
pub fn as_u64(&self) -> Result<u64, Error>
A Nat, as a u64. A number that is too large is an error at it.
Sourcepub fn as_i64(&self) -> Result<i64, Error>
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.