Struct cbor_data::Cbor[][src]

pub struct Cbor<'a>(_);

Wrapper around a byte slice that allows parsing as CBOR value.

For details on the format see RFC 7049.

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

Implementations

impl<'a> Cbor<'a>[src]

pub fn trusting(bytes: &'a [u8]) -> Self[src]

Wrap in Cbor for indexing.

No checks on the integrity are made, indexing methods may panic if encoded lengths are out of bound or when encountering indefinite size (byte) strings. If you want to carefully treat data obtained from unreliable sources, prefer CborOwned::canonical. The results of CborBuilder can also safely be fed to this method.

pub fn to_owned(&self) -> CborOwned[src]

Copy the underlying bytes to create a fully owned CBOR value.

No checks on the integrity are made, indexing methods may panic if encoded lengths are out of bound or when encountering indefinite size (byte) strings. If you want to carefully treat data obtained from unreliable sources, prefer CborOwned::canonical. The results of CborBuilder can also safely be fed to this method.

impl<'a> Cbor<'a>[src]

pub fn as_slice(&self) -> &'a [u8][src]

A view onto the underlying bytes

pub fn value(&self) -> Option<CborValue<'a>>[src]

Extract the single value represented by this piece of CBOR

pub fn index(&self, path: &str) -> Option<CborValue<'a>>[src]

Extract a value by indexing into arrays and dicts, with path elements separated by dot.

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.

The empty string will yield the same as calling value(). If path elements may contain . then use index_iter().

pub fn index_iter<'b>(
    &self,
    path: impl IntoIterator<Item = &'b str>
) -> Option<CborValue<'a>>
[src]

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.

The empty iterator will yield the same as calling value().

pub fn visit<Err, V: Visitor<'a, Err>>(
    &self,
    visitor: &mut V
) -> Result<bool, Err>
[src]

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

impl<'a> AsRef<[u8]> for Cbor<'a>[src]

impl<'a> Debug for Cbor<'a>[src]

impl<'a> Display for Cbor<'a>[src]

impl<'a> PartialEq<Cbor<'a>> for Cbor<'a>[src]

impl<'a> StructuralPartialEq for Cbor<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for Cbor<'a>

impl<'a> Send for Cbor<'a>

impl<'a> Sync for Cbor<'a>

impl<'a> Unpin for Cbor<'a>

impl<'a> UnwindSafe for Cbor<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

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

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.