Enum preserves::value::repr::Value

source ·
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 Values 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>

source

pub fn wrap(self) -> N

Converts self to a NestedValue by supplying an empty collection of annotations.

source

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).

source

pub fn is_boolean(&self) -> bool

True iff this is a Value::Boolean.

source

pub fn as_boolean(&self) -> Option<bool>

Yields Some iff this is a Value::Boolean.

source

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.

source

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

Yields Ok iff this is a Value::Boolean; else Error::Expected.

source

pub fn is_double(&self) -> bool

True iff this is a Value::Double.

source

pub fn as_double(&self) -> Option<&Double>

Yields Some iff this is a Value::Double.

source

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.

source

pub fn to_double(&self) -> Result<&Double, Error>

Yields Ok iff this is a Value::Double; else Error::Expected.

source

pub fn is_f64(&self) -> bool

source

pub fn as_f64(&self) -> Option<f64>

As Self::as_double, but yields f64 instead of Double.

source

pub fn as_f64_mut(&mut self) -> Option<&mut f64>

As Self::as_double_mut, but f64 instead of Double.

source

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

As Self::to_double, but with f64 instead of Double.

source

pub fn is_signedinteger(&self) -> bool

True iff this is a Value::SignedInteger.

source

pub fn as_signedinteger(&self) -> Option<&SignedInteger>

Yields Some iff this is a Value::SignedInteger.

source

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.

source

pub fn to_signedinteger(&self) -> Result<&SignedInteger, Error>

Yields Ok iff this is a Value::SignedInteger; else Error::Expected.

source

pub fn is_i(&self) -> bool

True iff Self::as_i yields Some.

source

pub fn as_i(&self) -> Option<i128>

Yields Some if self is a Value::SignedInteger that fits in i128.

source

pub fn to_i(&self) -> Result<i128, Error>

Yields Ok if self is a Value::SignedInteger that fits in i128; else Error::Expected.

source

pub fn is_u(&self) -> bool

True iff Self::as_u yields Some.

source

pub fn as_u(&self) -> Option<u128>

Yields Some if self is a Value::SignedInteger that fits in u128.

source

pub fn to_u(&self) -> Result<u128, Error>

Yields Ok if self is a Value::SignedInteger that fits in u128; else Error::Expected.

source

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

Yields Some if self is a Value::SignedInteger that fits in u8.

source

pub fn as_i8(&self) -> Option<i8>

Yields Some if self is a Value::SignedInteger that fits in i8.

source

pub fn as_u16(&self) -> Option<u16>

Yields Some if self is a Value::SignedInteger that fits in u16.

source

pub fn as_i16(&self) -> Option<i16>

Yields Some if self is a Value::SignedInteger that fits in i16.

source

pub fn as_u32(&self) -> Option<u32>

Yields Some if self is a Value::SignedInteger that fits in u32.

source

pub fn as_i32(&self) -> Option<i32>

Yields Some if self is a Value::SignedInteger that fits in i32.

source

pub fn as_u64(&self) -> Option<u64>

Yields Some if self is a Value::SignedInteger that fits in u64.

source

pub fn as_i64(&self) -> Option<i64>

Yields Some if self is a Value::SignedInteger that fits in i64.

source

pub fn as_u128(&self) -> Option<u128>

Yields Some if self is a Value::SignedInteger that fits in u128.

source

pub fn as_i128(&self) -> Option<i128>

Yields Some if self is a Value::SignedInteger that fits in i128.

source

pub fn as_usize(&self) -> Option<usize>

Yields Some if self is a Value::SignedInteger that fits in usize.

source

pub fn as_isize(&self) -> Option<isize>

Yields Some if self is a Value::SignedInteger that fits in isize.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn is_string(&self) -> bool

True iff this is a Value::String.

source

pub fn as_string(&self) -> Option<&String>

Yields Some iff this is a Value::String.

source

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.

source

pub fn into_string(self) -> Option<String>

Consumes self, yielding a String iff self is a Value::String.

source

pub fn to_string(&self) -> Result<&String, Error>

Yields Ok iff this is a Value::String; else Error::Expected.

source

pub fn bytestring<'a, V: Into<Cow<'a, [u8]>>>(v: V) -> Self

Constructs a Value::ByteString from v.

source

pub fn is_bytestring(&self) -> bool

True iff this is a Value::ByteString.

source

pub fn as_bytestring(&self) -> Option<&Vec<u8>>

Yields Some iff this is a Value::ByteString.

source

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.

source

pub fn into_bytestring(self) -> Option<Vec<u8>>

Consumes self, yielding a Vec<u8> iff self is a Value::ByteString.

source

pub fn to_bytestring(&self) -> Result<&Vec<u8>, Error>

Yields Ok iff this is a Value::ByteString; else Error::Expected.

source

pub fn symbol(s: &str) -> Value<N>

Constructs a Value::Symbol from v.

source

pub fn is_symbol(&self) -> bool

True iff this is a Value::Symbol.

source

pub fn as_symbol(&self) -> Option<&String>

Yields Some iff this is a Value::Symbol.

source

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.

source

pub fn into_symbol(self) -> Option<String>

Consumes self, yielding a String iff self is a Value::Symbol.

source

pub fn to_symbol(&self) -> Result<&String, Error>

Yields Ok iff this is a Value::Symbol; else Error::Expected.

source

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.

source

pub fn is_record(&self) -> bool

True iff this is a Value::Record.

source

pub fn as_record(&self, arity: Option<usize>) -> Option<&Record<N>>

Yields Some iff this is a Value::Record.

source

pub fn into_record(self) -> Option<Record<N>>

Consumes self, yielding a Record iff self is a Value::Record.

source

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.

source

pub fn to_record(&self, arity: Option<usize>) -> Result<&Record<N>, Error>

Yields Ok iff this is a Value::Record; else Error::Expected.

source

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.

source

pub fn simple_record0(label: &str) -> Value<N>

Constructs a record with label a symbol with text label, and no fields.

source

pub fn simple_record1(label: &str, field: N) -> Value<N>

Constructs a record with label a symbol with text label, and one field.

source

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.

source

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.

source

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.

source

pub fn to_option(&self) -> Result<Option<&N>, Error>

Serde’s “option” type is incoded in Preserves as <None> or <Some v>.

source

pub fn is_sequence(&self) -> bool

True iff this is a Value::Sequence.

source

pub fn as_sequence(&self) -> Option<&Vec<N>>

Yields Some iff this is a Value::Sequence.

source

pub fn into_sequence(self) -> Option<Vec<N>>

Consumes self, yielding a Vec<N> iff self is a Value::Sequence.

source

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.

source

pub fn to_sequence(&self) -> Result<&Vec<N>, Error>

Yields Ok iff this is a Value::Sequence; else Error::Expected.

source

pub fn is_set(&self) -> bool

True iff this is a Value::Set.

source

pub fn as_set(&self) -> Option<&Set<N>>

Yields Some iff this is a Value::Set.

source

pub fn into_set(self) -> Option<Set<N>>

Consumes self, yielding a Set<N> iff self is a Value::Set.

source

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.

source

pub fn to_set(&self) -> Result<&Set<N>, Error>

Yields Ok iff this is a Value::Set; else Error::Expected.

source

pub fn is_dictionary(&self) -> bool

True iff this is a Value::Dictionary.

source

pub fn as_dictionary(&self) -> Option<&Map<N, N>>

Yields Some iff this is a Value::Dictionary.

source

pub fn into_dictionary(self) -> Option<Map<N, N>>

Consumes self, yielding a Map<N, N> iff self is a Value::Dictionary.

source

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.

source

pub fn to_dictionary(&self) -> Result<&Map<N, N>, Error>

Yields Ok iff this is a Value::Dictionary; else Error::Expected.

source

pub fn is_embedded(&self) -> bool

True iff this is a Value::Embedded.

source

pub fn as_embedded(&self) -> Option<&N::Embedded>

Yields Some iff this is a Value::Embedded.

source

pub fn to_embedded(&self) -> Result<&N::Embedded, Error>

Yields Ok iff this is a Value::Embedded; else Error::Expected.

source

pub fn strip_annotations<M: NestedValue<Embedded = N::Embedded>>( &self ) -> Value<M>

Yields a deep copy of self with all annotations (recursively) removed.

source

pub fn copy_via<M: NestedValue, F, Err>( &self, f: &mut F ) -> Result<Value<M>, Err>
where F: FnMut(&N::Embedded) -> Result<Value<M>, Err>,

Yields a deep copy of self, mapping embedded values to a new type via f.

source

pub fn foreach_embedded<F, Err>(&self, f: &mut F) -> Result<(), Err>
where F: FnMut(&N::Embedded) -> Result<(), Err>,

Calls f once for each (recursively) embedded value in self.

Trait Implementations§

source§

impl<N: Clone + NestedValue> Clone for Value<N>
where N::Embedded: Clone,

source§

fn clone(&self) -> Value<N>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<N: NestedValue> Debug for Value<N>

source§

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

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

impl<N: NestedValue> From<&[u8]> for Value<N>

source§

fn from(v: &[u8]) -> Self

Converts to this type from the input type.
source§

impl<N: NestedValue> From<&BigInt> for Value<N>

source§

fn from(v: &BigInt) -> Self

Converts to this type from the input type.
source§

impl<N: NestedValue> From<&Double> for Value<N>

source§

fn from(v: &Double) -> Self

Converts to this type from the input type.
source§

impl<N: NestedValue> From<&SignedInteger> for Value<N>

source§

fn from(v: &SignedInteger) -> Self

Converts to this type from the input type.
source§

impl<N: NestedValue> From<&String> for Value<N>

source§

fn from(v: &String) -> Self

Converts to this type from the input type.
source§

impl<N: NestedValue> From<&bool> for Value<N>

source§

fn from(v: &bool) -> Self

Converts to this type from the input type.
source§

impl<N: NestedValue> From<&f64> for Value<N>

source§

fn from(v: &f64) -> Self

Converts to this type from the input type.
source§

impl<N: NestedValue> From<&str> for Value<N>

source§

fn from(v: &str) -> Self

Converts to this type from the input type.
source§

impl<N: NestedValue> From<BTreeMap<N, N>> for Value<N>

source§

fn from(v: Map<N, N>) -> Self

Converts to this type from the input type.
source§

impl<N: NestedValue> From<BTreeSet<N>> for Value<N>

source§

fn from(v: Set<N>) -> Self

Converts to this type from the input type.
source§

impl<N: NestedValue> From<BigInt> for Value<N>

source§

fn from(v: BigInt) -> Self

Converts to this type from the input type.
source§

impl<N: NestedValue> From<String> for Value<N>

source§

fn from(v: String) -> Self

Converts to this type from the input type.
source§

impl<N: NestedValue> From<Vec<N>> for Value<N>

source§

fn from(v: Vec<N>) -> Self

Converts to this type from the input type.
source§

impl<N: NestedValue> From<bool> for Value<N>

source§

fn from(v: bool) -> Self

Converts to this type from the input type.
source§

impl<N: NestedValue> From<f64> for Value<N>

source§

fn from(v: f64) -> Self

Converts to this type from the input type.
source§

impl<N: NestedValue> From<i128> for Value<N>

source§

fn from(v: i128) -> Self

Converts to this type from the input type.
source§

impl<N: NestedValue> From<i16> for Value<N>

source§

fn from(v: i16) -> Self

Converts to this type from the input type.
source§

impl<N: NestedValue> From<i32> for Value<N>

source§

fn from(v: i32) -> Self

Converts to this type from the input type.
source§

impl<N: NestedValue> From<i64> for Value<N>

source§

fn from(v: i64) -> Self

Converts to this type from the input type.
source§

impl<N: NestedValue> From<i8> for Value<N>

source§

fn from(v: i8) -> Self

Converts to this type from the input type.
source§

impl<N: NestedValue> From<isize> for Value<N>

source§

fn from(v: isize) -> Self

Converts to this type from the input type.
source§

impl<N: NestedValue> From<u128> for Value<N>

source§

fn from(v: u128) -> Self

Converts to this type from the input type.
source§

impl<N: NestedValue> From<u16> for Value<N>

source§

fn from(v: u16) -> Self

Converts to this type from the input type.
source§

impl<N: NestedValue> From<u32> for Value<N>

source§

fn from(v: u32) -> Self

Converts to this type from the input type.
source§

impl<N: NestedValue> From<u64> for Value<N>

source§

fn from(v: u64) -> Self

Converts to this type from the input type.
source§

impl<N: NestedValue> From<u8> for Value<N>

source§

fn from(v: u8) -> Self

Converts to this type from the input type.
source§

impl<N: NestedValue> From<usize> for Value<N>

source§

fn from(v: usize) -> Self

Converts to this type from the input type.
source§

impl<Err: Into<Error>, D: Embeddable + FromStr<Err = Err>, N: NestedValue<Embedded = D>> FromStr for Value<N>

§

type Err = Error

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl<N: Hash + NestedValue> Hash for Value<N>
where N::Embedded: Hash,

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<N: NestedValue> Index<&N> for Value<N>

§

type Output = N

The returned type after indexing.
source§

fn index(&self, i: &N) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<N: NestedValue> Index<usize> for Value<N>

§

type Output = N

The returned type after indexing.
source§

fn index(&self, i: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<N: NestedValue> IndexMut<usize> for Value<N>

source§

fn index_mut(&mut self, i: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<N: Ord + NestedValue> Ord for Value<N>
where N::Embedded: Ord,

source§

fn cmp(&self, other: &Value<N>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<N: PartialEq + NestedValue> PartialEq for Value<N>
where N::Embedded: PartialEq,

source§

fn eq(&self, other: &Value<N>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<N: PartialOrd + NestedValue> PartialOrd for Value<N>
where N::Embedded: PartialOrd,

source§

fn partial_cmp(&self, other: &Value<N>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<N: Eq + NestedValue> Eq for Value<N>
where N::Embedded: Eq,

source§

impl<N: NestedValue> StructuralPartialEq for Value<N>

Auto Trait Implementations§

§

impl<N> Freeze for Value<N>
where <N as NestedValue>::Embedded: Freeze,

§

impl<N> RefUnwindSafe for Value<N>

§

impl<N> Send for Value<N>
where <N as NestedValue>::Embedded: Send, N: Send,

§

impl<N> Sync for Value<N>
where <N as NestedValue>::Embedded: Sync, N: Sync,

§

impl<N> Unpin for Value<N>
where <N as NestedValue>::Embedded: Unpin, N: Unpin,

§

impl<N> UnwindSafe for Value<N>

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> ToOwned for T
where T: Clone,

§

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>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,