Enum cbor_diag::DataItem

source ·
pub enum DataItem {
    Integer {
        value: u64,
        bitwidth: IntegerWidth,
    },
    Negative {
        value: u64,
        bitwidth: IntegerWidth,
    },
    ByteString(ByteString),
    TextString(TextString),
    IndefiniteByteString(Vec<ByteString>),
    IndefiniteTextString(Vec<TextString>),
    Array {
        data: Vec<DataItem>,
        bitwidth: Option<IntegerWidth>,
    },
    Map {
        data: Vec<(DataItem, DataItem)>,
        bitwidth: Option<IntegerWidth>,
    },
    Tag {
        tag: Tag,
        bitwidth: IntegerWidth,
        value: Box<DataItem>,
    },
    Float {
        value: f64,
        bitwidth: FloatWidth,
    },
    Simple(Simple),
}
Expand description

A CBOR data item.

See RFC 7049 § 1.2: Data item.

Variants§

§

Integer

Fields

§value: u64

The value of this unsigned integer.

§bitwidth: IntegerWidth

The bitwidth used for encoding this integer.

An unsigned integer.

See RFC 7049 § 2.1: Major type 0.

§

Negative

Fields

§value: u64

The encoded value of this negative integer, the real value is -1 - value (requires use of i128 for full range support).

§bitwidth: IntegerWidth

The bitwidth used for encoding this integer.

A negative integer.

See RFC 7049 § 2.1: Major type 0.

§

ByteString(ByteString)

A string of raw bytes with no direct attached meaning.

See the docs for ByteString for more details.

§

TextString(TextString)

A UTF-8 encoded text string.

See the docs for TextString for more details.

§

IndefiniteByteString(Vec<ByteString>)

A series of ByteString chunks encoded as an indefinite length byte string.

See RFC 7049 § 2.2.2.

§

IndefiniteTextString(Vec<TextString>)

A series of TextString chunks encoded as an indefinite length text string.

See RFC 7049 § 2.2.2.

§

Array

Fields

§data: Vec<DataItem>

The data items in this array.

§bitwidth: Option<IntegerWidth>

The bitwidth used for encoding the array length.

If has the value None then this array is encoded using the indefinite length form, see RFC 7049 § 2.2.1.

An array of data items.

See RFC 7049 § 2.1: Major type 4.

§

Map

Fields

§data: Vec<(DataItem, DataItem)>

The pairs of data items in this map.

§bitwidth: Option<IntegerWidth>

The bitwidth used for encoding the map length.

If has the value None then this map is encoded using the indefinite length form, see RFC 7049 § 2.2.1.

A map of pairs of data items.

See RFC 7049 § 2.1: Major type 5.

§

Tag

Fields

§tag: Tag

The semantic tag to be applied to value.

§bitwidth: IntegerWidth

The bitwidth used to encode the semantic tag.

§value: Box<DataItem>

The data item which has the semantic tag applied to it.

Semantic tagging of another data item.

See the docs for Tag for more details.

§

Float

Fields

§value: f64

The floating point value.

§bitwidth: FloatWidth

The bitwidth used for encoding the value.

A floating point value.

See RFC 7049 § 2.3.

§

Simple(Simple)

A “simple value” data item.

See the docs for Simple for more details.

Implementations§

source§

impl DataItem

source

pub fn to_bytes(&self) -> Vec<u8>

source§

impl DataItem

source

pub fn to_diag(&self) -> String

source

pub fn to_diag_pretty(&self) -> String

source§

impl DataItem

source

pub fn to_hex(&self) -> String

Trait Implementations§

source§

impl Clone for DataItem

source§

fn clone(&self) -> DataItem

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 Debug for DataItem

source§

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

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

impl PartialEq<DataItem> for DataItem

source§

fn eq(&self, other: &DataItem) -> 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 StructuralPartialEq for DataItem

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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 Twhere 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.