Enum saltpig::value::Value[][src]

pub enum Value {
    PosInt(u64),
    NegInt(u64),
    Bytes(Vec<u8>),
    Text(String),
    Array(Vec<Value>),
    Map(BTreeMap<OrdValue<'static>, Value>),
    Tagged(u64Box<Value>),
    Float(f64),
    Bool(bool),
    Null,
    Undefined,
    UnknownSimple(UnknownSimple),
}

The generic CBOR type.

Each instance of Value represents a single CBOR data item. See the CBOR standard for more information on the CBOR data model (in particular, see section 2.1 for information on major types, and section 2.3 for information on simple values).

Values are usually created by using From or Into to convert from another Rust type. For ease of use, standard conversions are implemented from and to all the types that Value contains (and then some) as well as all the extension types.

(Value is generic in the sense that it represents any CBOR value (as opposed to extension types, which represent specific kinds of CBOR values), not in the sense that it has type parameters (which it doesn't).)

Comparisons

Value implements PartialEq for every type it can be converted from. It does not, however, implement PartialOrd: this was thought to be more trouble than it was worth, since many values would compare inequal without being greater than or less than. Users needing to compare Values with other types must first convert the Value to the other type, which forces them to explicitly consider the case where the Value was not, in fact, the desired type. Additionally, Value will never implement Eq or Ord, because it cannot know the equality and ordering semantics of all possible tags. However, it is expected that many extension types will implement Ord.

The type chosen for CBOR maps, BTreeMap, requires that its key type implement Ord. To enable this, a wrapper type OrdValue was created. OrdValue wraps an owned or borrowed Value and provides an Ord impl, with the caveat that it ignores the actual semantics of the values and instead simply compares their bytewise encodings. See OrdValue's documentation for more information.

Variants

A non-negative integer (major type 0). PosInt(n) represents the integer n.

A negative integer (major type 1). NegInt(n) represents the integer -n - 1.

A byte string (major type 2).

A text string (major type 3).

An array (major type 4).

A map (major type 5).

A tagged value (major type 6).

A float (major type 7, additional information 25, 26, or 27).

A boolean (simple value 20 or 21).

Null (simple value 22).

Undefined (simple value 23).

A simple value not covered by the other variants.

Methods

impl Value
[src]

Compares self with another Value for structural equality.

struct_eq() is, roughly, what #[derive(PartialEq)] would come up with. It checks whether the Values are "the same thing".

More formally, two Values are structurally equal if and only if they have the same variant and contents (using structural equality to compare any nested Values). Notably, every NaN is considered structurally equal to every other NaN.

More specifically:

  • Two Values with different types are never structurally equal.
  • Two arrays are structurally equal if and only if they have the same values in the same order.
  • Two maps are structurally equal if and only if they have the same set set of key-value pairs.
  • Two tagged values are structurally equal if and only if they have the same tag and their inner values are structurally equal.

impl Value
[src]

impl Value
[src]

Attempts to parse a Value from a buffered reader.

Attempts to parse a Value from a slice of bytes.

Encodes self into a new Vec<u8>.

Encodes self into the given writer.

There is no guarantee that this method uses the writer with any measure of efficiency. Thus, you probably want to pass in a buffered writer.

Encodes just the prefix of self into the given buffer.

Encodes the major type, additional info, and any length or tag into buffer. More specifically:

  • For byte strings, text strings, arrays, and maps: the major type, additional info, and length are encoded (but not the contents)
  • For tagged values: the major type, additional info, and tag are encoded (but not the value following the tag).
  • For all other values, the entire value is encoded.

Writes at least 1 and at most 9 bytes into buffer.

Returns the portion of buffer that was written to.

Panics

Panics if buffer is not large enough to hold self's prefix (a buffer of length 9 is always large enough).

Returns self's major type.

Returns self's additional information value.

(Additional information values are always in the range 0..=31.)

Returns self's encoded major and additional information values.

In other words, returns the first byte of self's encoding.

Trait Implementations

impl From<EncodedCbor> for Value
[src]

Renders self into a generic CBOR value.

Equivalent to EncodedCbor::embed().

Performs the conversion.

impl TryFrom<Value> for EncodedCbor
[src]

Attempts to parse an EncodedCbor value out of a Value.

Equivalent to EncodedCbor::extract().

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl From<Ident> for Value
[src]

Renders self into a generic CBOR value.

Equivalent to Ident::embed().

Performs the conversion.

impl TryFrom<Value> for Ident
[src]

Attempts to parse an Ident value out of a Value.

Equivalent to Ident::extract().

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl PartialEq for Value
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialEq<usize> for Value
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialEq<isize> for Value
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialEq<[u8]> for Value
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialEq<Vec<u8>> for Value
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialEq<str> for Value
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialEq<String> for Value
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialEq<u8> for Value
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialEq<i8> for Value
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialEq<u16> for Value
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialEq<i16> for Value
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialEq<u32> for Value
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialEq<i32> for Value
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialEq<u64> for Value
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialEq<i64> for Value
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialEq<u128> for Value
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialEq<i128> for Value
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialEq<bool> for Value
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialEq<f16> for Value
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialEq<f32> for Value
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialEq<f64> for Value
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl From<Value> for OrdValue<'static>
[src]

Performs the conversion.

impl<'v> From<&'v Value> for OrdValue<'v>
[src]

Performs the conversion.

impl<'w> AsRef<Value> for OrdValue<'w>
[src]

Performs the conversion.

impl<'a, T> From<&'a T> for Value where
    T: Into<Value> + Copy
[src]

Performs the conversion.

impl<T> From<Option<T>> for Value where
    T: Into<Value>, 
[src]

Performs the conversion.

impl From<Value> for Cow<'static, Value>
[src]

Performs the conversion.

impl<'a> From<&'a Value> for Cow<'a, Value>
[src]

Performs the conversion.

impl From<u8> for Value
[src]

Performs the conversion.

impl From<u16> for Value
[src]

Performs the conversion.

impl From<u32> for Value
[src]

Performs the conversion.

impl From<u64> for Value
[src]

Performs the conversion.

impl From<Vec<u8>> for Value
[src]

Performs the conversion.

impl From<String> for Value
[src]

Performs the conversion.

impl From<Vec<Value>> for Value
[src]

Performs the conversion.

impl From<BTreeMap<OrdValue<'static>, Value>> for Value
[src]

Performs the conversion.

impl From<f16> for Value
[src]

Performs the conversion.

impl From<f32> for Value
[src]

Performs the conversion.

impl From<f64> for Value
[src]

Performs the conversion.

impl From<bool> for Value
[src]

Performs the conversion.

impl From<UnknownSimple> for Value
[src]

Performs the conversion.

impl TryFrom<Value> for Vec<u8>
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl TryFrom<Value> for String
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl TryFrom<Value> for Vec<Value>
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl TryFrom<Value> for BTreeMap<OrdValue<'static>, Value>
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl TryFrom<Value> for UnknownSimple
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<'v> TryFrom<&'v Value> for u8
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl TryFrom<Value> for u8
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<'v> TryFrom<&'v Value> for i8
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl TryFrom<Value> for i8
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<'v> TryFrom<&'v Value> for u16
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl TryFrom<Value> for u16
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<'v> TryFrom<&'v Value> for i16
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl TryFrom<Value> for i16
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<'v> TryFrom<&'v Value> for u32
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl TryFrom<Value> for u32
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<'v> TryFrom<&'v Value> for i32
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl TryFrom<Value> for i32
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<'v> TryFrom<&'v Value> for u64
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl TryFrom<Value> for u64
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<'v> TryFrom<&'v Value> for i64
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl TryFrom<Value> for i64
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<'v> TryFrom<&'v Value> for u128
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl TryFrom<Value> for u128
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<'v> TryFrom<&'v Value> for i128
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl TryFrom<Value> for i128
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl From<i8> for Value
[src]

Performs the conversion.

impl From<i16> for Value
[src]

Performs the conversion.

impl From<i32> for Value
[src]

Performs the conversion.

impl From<i64> for Value
[src]

Performs the conversion.

impl TryFrom<u128> for Value
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl TryFrom<i128> for Value
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<'v> TryFrom<&'v Value> for f16
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<'v> TryFrom<&'v Value> for f32
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<'v> TryFrom<&'v Value> for f64
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl TryFrom<Value> for f16
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl TryFrom<Value> for f32
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl TryFrom<Value> for f64
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<'v> TryFrom<&'v Value> for bool
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl TryFrom<Value> for bool
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<'v> TryFrom<&'v Value> for char
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl TryFrom<Value> for char
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl Debug for Value
[src]

Formats the value using the given formatter. Read more

impl Clone for Value
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl Send for Value

impl Sync for Value