pub enum Value<N: NestedValue> {
Boolean(bool),
Double(Double),
SignedInteger(SignedInteger),
String(String),
ByteString(Vec<u8>),
Symbol(String),
Record(Record<N>),
Sequence(Vec<N>),
Set(Set<N>),
Dictionary(Map<N, N>),
Embedded(N::Embedded),
}
Expand description
The Value
s from the specification.
Variants§
Boolean(bool)
Double(Double)
SignedInteger(SignedInteger)
String(String)
ByteString(Vec<u8>)
Symbol(String)
Record(Record<N>)
Sequence(Vec<N>)
Set(Set<N>)
Dictionary(Map<N, N>)
Embedded(N::Embedded)
Implementations§
source§impl<N: NestedValue> Value<N>
impl<N: NestedValue> Value<N>
sourcepub fn wrap(self) -> N
pub fn wrap(self) -> N
Converts self
to a NestedValue by supplying an empty collection of annotations.
sourcepub fn children(&self) -> Vec<N>
pub fn children(&self) -> Vec<N>
Retrieve a vector of the “children” of self
.
For atoms, this is an empty vector. For records, it’s all the fields (but not the label). For sequences and sets, it’s the contained values. For dictionaries, it’s all the values in the key-value mappings (but not the keys).
sourcepub fn is_boolean(&self) -> bool
pub fn is_boolean(&self) -> bool
True iff this is a Value::Boolean.
sourcepub fn as_boolean(&self) -> Option<bool>
pub fn as_boolean(&self) -> Option<bool>
Yields Some
iff this is a Value::Boolean.
sourcepub fn as_boolean_mut(&mut self) -> Option<&mut bool>
pub fn as_boolean_mut(&mut self) -> Option<&mut bool>
Retrieve a mutable reference to the contained boolean value iff this is a Value::Boolean.
sourcepub fn to_boolean(&self) -> Result<bool, Error>
pub fn to_boolean(&self) -> Result<bool, Error>
Yields Ok
iff this is a Value::Boolean; else Error::Expected.
sourcepub fn is_double(&self) -> bool
pub fn is_double(&self) -> bool
True iff this is a Value::Double.
sourcepub fn as_double(&self) -> Option<&Double>
pub fn as_double(&self) -> Option<&Double>
Yields Some
iff this is a Value::Double.
sourcepub fn as_double_mut(&mut self) -> Option<&mut Double>
pub fn as_double_mut(&mut self) -> Option<&mut Double>
Retrieve a mutable reference to the contained Double value iff this is a Value::Double.
sourcepub fn to_double(&self) -> Result<&Double, Error>
pub fn to_double(&self) -> Result<&Double, Error>
Yields Ok
iff this is a Value::Double; else Error::Expected.
sourcepub fn is_f64(&self) -> bool
pub fn is_f64(&self) -> bool
As Self::is_double.
sourcepub fn as_f64_mut(&mut self) -> Option<&mut f64>
pub fn as_f64_mut(&mut self) -> Option<&mut f64>
As Self::as_double_mut, but f64 instead of Double.
sourcepub fn is_signedinteger(&self) -> bool
pub fn is_signedinteger(&self) -> bool
True iff this is a Value::SignedInteger.
sourcepub fn as_signedinteger(&self) -> Option<&SignedInteger>
pub fn as_signedinteger(&self) -> Option<&SignedInteger>
Yields Some
iff this is a Value::SignedInteger.
sourcepub fn as_signedinteger_mut(&mut self) -> Option<&mut SignedInteger>
pub fn as_signedinteger_mut(&mut self) -> Option<&mut SignedInteger>
Retrieve a mutable reference to the contained SignedInteger value iff this is a Value::SignedInteger.
sourcepub fn to_signedinteger(&self) -> Result<&SignedInteger, Error>
pub fn to_signedinteger(&self) -> Result<&SignedInteger, Error>
Yields Ok
iff this is a Value::SignedInteger; else Error::Expected.
sourcepub fn is_i(&self) -> bool
pub fn is_i(&self) -> bool
True iff Self::as_i yields Some
.
sourcepub fn as_i(&self) -> Option<i128>
pub fn as_i(&self) -> Option<i128>
Yields Some
if self
is a Value::SignedInteger that fits in i128.
sourcepub fn to_i(&self) -> Result<i128, Error>
pub fn to_i(&self) -> Result<i128, Error>
Yields Ok
if self
is a Value::SignedInteger that fits in i128; else Error::Expected.
sourcepub fn is_u(&self) -> bool
pub fn is_u(&self) -> bool
True iff Self::as_u yields Some
.
sourcepub fn as_u(&self) -> Option<u128>
pub fn as_u(&self) -> Option<u128>
Yields Some
if self
is a Value::SignedInteger that fits in u128.
sourcepub fn to_u(&self) -> Result<u128, Error>
pub fn to_u(&self) -> Result<u128, Error>
Yields Ok
if self
is a Value::SignedInteger that fits in u128; else Error::Expected.
sourcepub fn as_u8(&self) -> Option<u8>
pub fn as_u8(&self) -> Option<u8>
Yields Some
if self
is a Value::SignedInteger that fits in u8.
sourcepub fn as_i8(&self) -> Option<i8>
pub fn as_i8(&self) -> Option<i8>
Yields Some
if self
is a Value::SignedInteger that fits in i8.
sourcepub fn as_u16(&self) -> Option<u16>
pub fn as_u16(&self) -> Option<u16>
Yields Some
if self
is a Value::SignedInteger that fits in u16.
sourcepub fn as_i16(&self) -> Option<i16>
pub fn as_i16(&self) -> Option<i16>
Yields Some
if self
is a Value::SignedInteger that fits in i16.
sourcepub fn as_u32(&self) -> Option<u32>
pub fn as_u32(&self) -> Option<u32>
Yields Some
if self
is a Value::SignedInteger that fits in u32.
sourcepub fn as_i32(&self) -> Option<i32>
pub fn as_i32(&self) -> Option<i32>
Yields Some
if self
is a Value::SignedInteger that fits in i32.
sourcepub fn as_u64(&self) -> Option<u64>
pub fn as_u64(&self) -> Option<u64>
Yields Some
if self
is a Value::SignedInteger that fits in u64.
sourcepub fn as_i64(&self) -> Option<i64>
pub fn as_i64(&self) -> Option<i64>
Yields Some
if self
is a Value::SignedInteger that fits in i64.
sourcepub fn as_u128(&self) -> Option<u128>
pub fn as_u128(&self) -> Option<u128>
Yields Some
if self
is a Value::SignedInteger that fits in u128.
sourcepub fn as_i128(&self) -> Option<i128>
pub fn as_i128(&self) -> Option<i128>
Yields Some
if self
is a Value::SignedInteger that fits in i128.
sourcepub fn as_usize(&self) -> Option<usize>
pub fn as_usize(&self) -> Option<usize>
Yields Some
if self
is a Value::SignedInteger that fits in usize.
sourcepub fn as_isize(&self) -> Option<isize>
pub fn as_isize(&self) -> Option<isize>
Yields Some
if self
is a Value::SignedInteger that fits in isize.
sourcepub fn to_i8(&self) -> Result<i8, Error>
pub fn to_i8(&self) -> Result<i8, Error>
Yields Ok
if self
is a Value::SignedInteger that fits in i8;
otherwise, Error::Expected or Error::NumberOutOfRange.
sourcepub fn to_u8(&self) -> Result<u8, Error>
pub fn to_u8(&self) -> Result<u8, Error>
Yields Ok
if self
is a Value::SignedInteger that fits in u8;
otherwise, Error::Expected or Error::NumberOutOfRange.
sourcepub fn to_i16(&self) -> Result<i16, Error>
pub fn to_i16(&self) -> Result<i16, Error>
Yields Ok
if self
is a Value::SignedInteger that fits in i16;
otherwise, Error::Expected or Error::NumberOutOfRange.
sourcepub fn to_u16(&self) -> Result<u16, Error>
pub fn to_u16(&self) -> Result<u16, Error>
Yields Ok
if self
is a Value::SignedInteger that fits in u16;
otherwise, Error::Expected or Error::NumberOutOfRange.
sourcepub fn to_i32(&self) -> Result<i32, Error>
pub fn to_i32(&self) -> Result<i32, Error>
Yields Ok
if self
is a Value::SignedInteger that fits in i32;
otherwise, Error::Expected or Error::NumberOutOfRange.
sourcepub fn to_u32(&self) -> Result<u32, Error>
pub fn to_u32(&self) -> Result<u32, Error>
Yields Ok
if self
is a Value::SignedInteger that fits in u32;
otherwise, Error::Expected or Error::NumberOutOfRange.
sourcepub fn to_i64(&self) -> Result<i64, Error>
pub fn to_i64(&self) -> Result<i64, Error>
Yields Ok
if self
is a Value::SignedInteger that fits in i64;
otherwise, Error::Expected or Error::NumberOutOfRange.
sourcepub fn to_u64(&self) -> Result<u64, Error>
pub fn to_u64(&self) -> Result<u64, Error>
Yields Ok
if self
is a Value::SignedInteger that fits in u64;
otherwise, Error::Expected or Error::NumberOutOfRange.
sourcepub fn to_i128(&self) -> Result<i128, Error>
pub fn to_i128(&self) -> Result<i128, Error>
Yields Ok
if self
is a Value::SignedInteger that fits in i128;
otherwise, Error::Expected or Error::NumberOutOfRange.
sourcepub fn to_u128(&self) -> Result<u128, Error>
pub fn to_u128(&self) -> Result<u128, Error>
Yields Ok
if self
is a Value::SignedInteger that fits in u128;
otherwise, Error::Expected or Error::NumberOutOfRange.
sourcepub fn to_isize(&self) -> Result<isize, Error>
pub fn to_isize(&self) -> Result<isize, Error>
Yields Ok
if self
is a Value::SignedInteger that fits in isize;
otherwise, Error::Expected or Error::NumberOutOfRange.
sourcepub fn to_usize(&self) -> Result<usize, Error>
pub fn to_usize(&self) -> Result<usize, Error>
Yields Ok
if self
is a Value::SignedInteger that fits in usize;
otherwise, Error::Expected or Error::NumberOutOfRange.
sourcepub fn to_char(&self) -> Result<char, Error>
pub fn to_char(&self) -> Result<char, Error>
Yields Ok
if self
is a record with label a symbol UnicodeScalar
and single field
a SignedInteger that can represent a valid Unicode scalar value. Otherwise,
Error::Expected or Error::InvalidUnicodeScalar. otherwise, Error::Expected or
Error::NumberOutOfRange.
sourcepub fn is_string(&self) -> bool
pub fn is_string(&self) -> bool
True iff this is a Value::String.
sourcepub fn as_string(&self) -> Option<&String>
pub fn as_string(&self) -> Option<&String>
Yields Some
iff this is a Value::String.
sourcepub fn as_string_mut(&mut self) -> Option<&mut String>
pub fn as_string_mut(&mut self) -> Option<&mut String>
Retrieve a mutable reference to the contained String value iff this is a Value::String.
sourcepub fn into_string(self) -> Option<String>
pub fn into_string(self) -> Option<String>
Consumes self
, yielding a String
iff self
is a Value::String.
sourcepub fn to_string(&self) -> Result<&String, Error>
pub fn to_string(&self) -> Result<&String, Error>
Yields Ok
iff this is a Value::String; else Error::Expected.
sourcepub fn bytestring<'a, V: Into<Cow<'a, [u8]>>>(v: V) -> Self
pub fn bytestring<'a, V: Into<Cow<'a, [u8]>>>(v: V) -> Self
Constructs a Value::ByteString from v
.
sourcepub fn is_bytestring(&self) -> bool
pub fn is_bytestring(&self) -> bool
True iff this is a Value::ByteString.
sourcepub fn as_bytestring(&self) -> Option<&Vec<u8>>
pub fn as_bytestring(&self) -> Option<&Vec<u8>>
Yields Some
iff this is a Value::ByteString.
sourcepub fn as_bytestring_mut(&mut self) -> Option<&mut Vec<u8>>
pub fn as_bytestring_mut(&mut self) -> Option<&mut Vec<u8>>
Retrieve a mutable reference to the contained bytes value iff this is a Value::ByteString.
sourcepub fn into_bytestring(self) -> Option<Vec<u8>>
pub fn into_bytestring(self) -> Option<Vec<u8>>
Consumes self
, yielding a Vec<u8>
iff self
is a Value::ByteString.
sourcepub fn to_bytestring(&self) -> Result<&Vec<u8>, Error>
pub fn to_bytestring(&self) -> Result<&Vec<u8>, Error>
Yields Ok
iff this is a Value::ByteString; else Error::Expected.
sourcepub fn symbol(s: &str) -> Value<N>
pub fn symbol(s: &str) -> Value<N>
Constructs a Value::Symbol from v
.
sourcepub fn is_symbol(&self) -> bool
pub fn is_symbol(&self) -> bool
True iff this is a Value::Symbol.
sourcepub fn as_symbol(&self) -> Option<&String>
pub fn as_symbol(&self) -> Option<&String>
Yields Some
iff this is a Value::Symbol.
sourcepub fn as_symbol_mut(&mut self) -> Option<&mut String>
pub fn as_symbol_mut(&mut self) -> Option<&mut String>
Retrieve a mutable reference to the contained Symbol’s string iff this is a Value::Symbol.
sourcepub fn into_symbol(self) -> Option<String>
pub fn into_symbol(self) -> Option<String>
Consumes self
, yielding a String
iff self
is a Value::Symbol.
sourcepub fn to_symbol(&self) -> Result<&String, Error>
pub fn to_symbol(&self) -> Result<&String, Error>
Yields Ok
iff this is a Value::Symbol; else Error::Expected.
sourcepub fn record(label: N, expected_arity: usize) -> Record<N>
pub fn record(label: N, expected_arity: usize) -> Record<N>
Constructs a record with the given label and expected arity. The new record will
initially not have any fields, but will be allocated with capacity for expected_arity
fields.
sourcepub fn is_record(&self) -> bool
pub fn is_record(&self) -> bool
True iff this is a Value::Record.
sourcepub fn as_record(&self, arity: Option<usize>) -> Option<&Record<N>>
pub fn as_record(&self, arity: Option<usize>) -> Option<&Record<N>>
Yields Some
iff this is a Value::Record.
sourcepub fn into_record(self) -> Option<Record<N>>
pub fn into_record(self) -> Option<Record<N>>
Consumes self
, yielding a Record
iff self
is a Value::Record.
sourcepub fn as_record_mut(&mut self, arity: Option<usize>) -> Option<&mut Record<N>>
pub fn as_record_mut(&mut self, arity: Option<usize>) -> Option<&mut Record<N>>
Retrieve a mutable reference to the contained Record value iff this is a Value::Record.
sourcepub fn to_record(&self, arity: Option<usize>) -> Result<&Record<N>, Error>
pub fn to_record(&self, arity: Option<usize>) -> Result<&Record<N>, Error>
Yields Ok
iff this is a Value::Record; else Error::Expected.
sourcepub fn simple_record(label: &str, expected_arity: usize) -> Record<N>
pub fn simple_record(label: &str, expected_arity: usize) -> Record<N>
Like Self::record, but for the common case where the label is to be a Symbol
with a
given text.
sourcepub fn simple_record0(label: &str) -> Value<N>
pub fn simple_record0(label: &str) -> Value<N>
Constructs a record with label a symbol with text label
, and no fields.
sourcepub fn simple_record1(label: &str, field: N) -> Value<N>
pub fn simple_record1(label: &str, field: N) -> Value<N>
Constructs a record with label a symbol with text label
, and one field.
sourcepub fn is_simple_record(&self, label: &str, arity: Option<usize>) -> bool
pub fn is_simple_record(&self, label: &str, arity: Option<usize>) -> bool
True iff self
is a record with label a symbol with text label
and arity matching
arity
: any arity, if arity == None
, or the specific usize
concerned otherwise.
sourcepub fn as_simple_record(
&self,
label: &str,
arity: Option<usize>
) -> Option<&[N]>
pub fn as_simple_record( &self, label: &str, arity: Option<usize> ) -> Option<&[N]>
Yields Some
containing a reference to the record’s fields iff
Self::is_simple_record
(label, arity)
returns true.
sourcepub fn to_simple_record(
&self,
label: &str,
arity: Option<usize>
) -> Result<&[N], Error>
pub fn to_simple_record( &self, label: &str, arity: Option<usize> ) -> Result<&[N], Error>
Like Self::as_simple_record, but yields Error::Expected on failure.
sourcepub fn to_option(&self) -> Result<Option<&N>, Error>
pub fn to_option(&self) -> Result<Option<&N>, Error>
Serde’s “option” type is incoded in Preserves as <None>
or <Some v>
.
sourcepub fn is_sequence(&self) -> bool
pub fn is_sequence(&self) -> bool
True iff this is a Value::Sequence.
sourcepub fn as_sequence(&self) -> Option<&Vec<N>>
pub fn as_sequence(&self) -> Option<&Vec<N>>
Yields Some
iff this is a Value::Sequence.
sourcepub fn into_sequence(self) -> Option<Vec<N>>
pub fn into_sequence(self) -> Option<Vec<N>>
Consumes self
, yielding a Vec<N>
iff self
is a Value::Sequence.
sourcepub fn as_sequence_mut(&mut self) -> Option<&mut Vec<N>>
pub fn as_sequence_mut(&mut self) -> Option<&mut Vec<N>>
Retrieve a mutable reference to the contained Vec<N>
iff this is a Value::Sequence.
sourcepub fn to_sequence(&self) -> Result<&Vec<N>, Error>
pub fn to_sequence(&self) -> Result<&Vec<N>, Error>
Yields Ok
iff this is a Value::Sequence; else Error::Expected.
sourcepub fn is_set(&self) -> bool
pub fn is_set(&self) -> bool
True iff this is a Value::Set.
sourcepub fn as_set(&self) -> Option<&Set<N>>
pub fn as_set(&self) -> Option<&Set<N>>
Yields Some
iff this is a Value::Set.
sourcepub fn into_set(self) -> Option<Set<N>>
pub fn into_set(self) -> Option<Set<N>>
Consumes self
, yielding a Set<N>
iff self
is a Value::Set.
sourcepub fn as_set_mut(&mut self) -> Option<&mut Set<N>>
pub fn as_set_mut(&mut self) -> Option<&mut Set<N>>
Retrieve a mutable reference to the contained Set value iff this is a Value::Set.
sourcepub fn to_set(&self) -> Result<&Set<N>, Error>
pub fn to_set(&self) -> Result<&Set<N>, Error>
Yields Ok
iff this is a Value::Set; else Error::Expected.
sourcepub fn is_dictionary(&self) -> bool
pub fn is_dictionary(&self) -> bool
True iff this is a Value::Dictionary.
sourcepub fn as_dictionary(&self) -> Option<&Map<N, N>>
pub fn as_dictionary(&self) -> Option<&Map<N, N>>
Yields Some
iff this is a Value::Dictionary.
sourcepub fn into_dictionary(self) -> Option<Map<N, N>>
pub fn into_dictionary(self) -> Option<Map<N, N>>
Consumes self
, yielding a Map<N, N>
iff self
is a Value::Dictionary.
sourcepub fn as_dictionary_mut(&mut self) -> Option<&mut Map<N, N>>
pub fn as_dictionary_mut(&mut self) -> Option<&mut Map<N, N>>
Retrieve a mutable reference to the contained Map value iff this is a Value::Dictionary.
sourcepub fn to_dictionary(&self) -> Result<&Map<N, N>, Error>
pub fn to_dictionary(&self) -> Result<&Map<N, N>, Error>
Yields Ok
iff this is a Value::Dictionary; else Error::Expected.
sourcepub fn is_embedded(&self) -> bool
pub fn is_embedded(&self) -> bool
True iff this is a Value::Embedded.
sourcepub fn as_embedded(&self) -> Option<&N::Embedded>
pub fn as_embedded(&self) -> Option<&N::Embedded>
Yields Some
iff this is a Value::Embedded.
sourcepub fn to_embedded(&self) -> Result<&N::Embedded, Error>
pub fn to_embedded(&self) -> Result<&N::Embedded, Error>
Yields Ok
iff this is a Value::Embedded; else Error::Expected.
sourcepub fn strip_annotations<M: NestedValue<Embedded = N::Embedded>>(
&self
) -> Value<M>
pub fn strip_annotations<M: NestedValue<Embedded = N::Embedded>>( &self ) -> Value<M>
Yields a deep copy of self
with all annotations (recursively) removed.
Trait Implementations§
source§impl<N: NestedValue> Debug for Value<N>
impl<N: NestedValue> Debug for Value<N>
source§impl<N: NestedValue> From<&SignedInteger> for Value<N>
impl<N: NestedValue> From<&SignedInteger> for Value<N>
source§fn from(v: &SignedInteger) -> Self
fn from(v: &SignedInteger) -> Self
source§impl<Err: Into<Error>, D: Embeddable + FromStr<Err = Err>, N: NestedValue<Embedded = D>> FromStr for Value<N>
impl<Err: Into<Error>, D: Embeddable + FromStr<Err = Err>, N: NestedValue<Embedded = D>> FromStr for Value<N>
source§impl<N: Ord + NestedValue> Ord for Value<N>
impl<N: Ord + NestedValue> Ord for Value<N>
source§impl<N: PartialEq + NestedValue> PartialEq for Value<N>
impl<N: PartialEq + NestedValue> PartialEq for Value<N>
source§impl<N: PartialOrd + NestedValue> PartialOrd for Value<N>where
N::Embedded: PartialOrd,
impl<N: PartialOrd + NestedValue> PartialOrd for Value<N>where
N::Embedded: PartialOrd,
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more