pub struct CborOwned(_);
Expand description

Wrapper around a vector of bytes, for parsing as CBOR.

For details on the format see RFC 8949.

When interpreting CBOR messages from the outside (e.g. from the network) it is advisable to ingest those using the canonical constructor. In case the message was encoded for example using CborBuilder it is sufficient to use the trusting constructor.

Canonicalisation rqeuires an intermediary data buffer, which can be supplied (and reused) by the caller to save on allocations.

Implementations

Copy the bytes and wrap for indexing.

No checks on the integrity are made, indexing methods may panic if encoded lengths are out of bound. If you want to carefully treat data obtained from unreliable sources, prefer canonical().

Copy the bytes while checking for integrity and replacing indefinite (byte) strings with definite ones.

This constructor will go through and decode the whole provided CBOR bytes and write them into a vector, thereby

  • writing large arrays and dicts using indefinite size format
  • writing numbers in their smallest form

For more configuration options like reusing a scratch space or preferring definite size encoding see CborBuilder.

Hand out the underlying SmallVec as a Vec

Will only allocate if the item is at most 16 bytes long.

Methods from Deref<Target = Cbor>

A view onto the underlying bytes

Interpret the CBOR item at a higher level

While kind gives you precise information on how the item is encoded, this method interprets the tag-based encoding according to the standard, adding for example big integers, decimals, and floats, or turning base64-encoded text strings into binary strings.

An iterator over the tags present on this item, from outermost to innermost

The low-level encoding of this item, without its tags

The low-level encoding of this item with its tags

More efficient shortcut for .decode().is_null() with error reporting.

More efficient shortcut for .decode().as_bool() with error reporting.

More efficient shortcut for .decode().to_number() with error reporting.

More efficient shortcut for .decode().as_timestamp() with error reporting.

More efficient shortcut for .decode().to_bytes() with error reporting.

More efficient shortcut for .decode().to_str() with error reporting.

More efficient shortcut for .decode().to_array() with error reporting.

More efficient shortcut for .decode().to_dict() with error reporting.

Extract a value by indexing into arrays and dicts, with path elements yielded by an iterator.

Returns None if an index doesn’t exist or the indexed object is neither an array nor a dict. When the object under consideration is an array, the next path element must represent an integer number.

Providing an empty iterator will yield the current Cbor item.

Returns a borrowed Cbor unless the traversal entered a TAG_CBOR_ITEM byte string with indefinite encoding (in which case the bytes need to be assembled into a Vec before continuing). This cannot happen if the item being indexed stems from CborOwned::canonical.

Extract a value by indexing into arrays and dicts, with path elements yielded by an iterator.

Returns None if an index doesn’t exist or the indexed object is neither an array nor a dict. When the object under consideration is an array, the next path element must represent an integer number.

Providing an empty iterator will yield the current Cbor item.

Panics

Panics if this CBOR item contains a TAG_CBOR_ITEM byte string that has been index into by this path traversal. Use CborOwned::canonical to ensure that this cannot happen.

Visit the interesting parts of this CBOR item as guided by the given Visitor.

Returns false if the visit was not even begun due to invalid or non-canonical CBOR.

Trait Implementations

Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Immutably borrows from an owned value. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
The resulting type after dereferencing.
Dereferences the value.
Formats the value using the given formatter. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
The type returned in the event of a conversion error.
Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.