[][src]Struct cbor_data::Cbor

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.

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.

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

pub fn is_array(&self) -> bool[src]

Check if this CBOR contains an array as its top-level item. Returns false also in case of data format problems.

pub fn is_dict(&self) -> bool[src]

Check if this CBOR contains an dict as its top-level item. Returns false also in case of data format problems.

Trait Implementations

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

impl<'a> Debug 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>[src]

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

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

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

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

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