CborPath

Struct CborPath 

Source
pub struct CborPath(/* private fields */);
Expand description

Represents a CBORPath expression

Once constructed, this structure can be used efficiently multiple times to apply the CBOR Path expression on different CBOR documents.

Implementations§

Source§

impl CborPath

Source

pub fn builder() -> PathBuilder

Initialize a CborPath instance from a builder

§Return

A new CborPath instance

Source

pub fn from_bytes(cbor: &[u8]) -> Result<Self, Error>

Initialize a CborPath instance from a CBOR binary buffer

§Arguments
  • cbor - the CBOR input document
§Return

A new CborPath instance or an error if the provided buffer is neither a valid CBOR buffer nor a valid CBORPath expression.

Source

pub fn from_value(cbor: &Cbor) -> Result<Self, Error>

Initialize a CborPath instance from a CBOR value reference

§Arguments
  • cbor - the CBOR input document
§Return

A new CborPath instance or an error if the provided buffer is the provided [CBOR value] is not a valid CBORPath expression.

Source

pub fn root() -> Self

Initialize a CborPath instance as a root path

Source

pub fn is_root(&self) -> bool

Return true if the CBORPath is a root path ($) else false

Source

pub fn read<'a>(&self, cbor: &'a Cbor) -> Vec<&'a Cbor>

Applies the CBORPath expression to the input CBOR document

§Arguments
  • cbor - the CBOR input document
§Return

A binarized CBOR document

The returned value is always in a the form of a CBOR Array which contains all the results CBOR nodes

The evaluation in itself does not raise any error: if the CBORPath expression does not match the input value, an empty CBOR Array will be returned.

Source

pub fn read_from_bytes(&self, cbor: &[u8]) -> Result<Vec<u8>, Error>

Applies the CBORPath expression to the input CBOR document

§Arguments
  • cbor - the CBOR input document
§Return

A binarized CBOR document.

The returned value is always in a the form of a CBOR Array which contains all the results CBOR nodes

The evaluation in itself does not raise any error: if the CBORPath expression does not match the input value, an empty CBOR Array will be returned.

Errors can only occur if the input buffer is not a valid CBOR document.

Source

pub fn get_paths(&self, cbor: &Cbor) -> Vec<Path>

Applies the CBORPath expression to the input CBOR document

§Arguments
  • cbor - the CBOR input document
§Return

A path list to matched nodes.

The evaluation in itself does not raise any error: if the CBORPath expression does not match the input value, an empty list will be returned.

Source

pub fn get_paths_from_bytes(&self, cbor: &[u8]) -> Result<Vec<Path>, Error>

Applies the CBORPath expression to the input CBOR document

§Arguments
  • cbor - the CBOR input document
§Return

A path list to matched nodes.

The evaluation in itself does not raise any error: if the CBORPath expression does not match the input value, an empty list will be returned.

Errors can only occur if the input buffer is not a valid CBOR document.

Source

pub fn write<'a, F>( &self, cbor: &'a Cbor, map_function: F, ) -> Result<Option<CborOwned>, Error>
where F: FnMut(&'a Cbor) -> Result<Option<Cow<'a, Cbor>>, Error>,

Replaces or deletes the value on the given path with the result of the map_function

§Arguments
  • cbor - the CBOR input document
  • map_function - Returns a converted CBOR sub-document to replace the input CBOR sub-document or None to delete the input sub-document.
§Return

The updated CBOR document or None if the CBORPath expression does not match the input value.

The evaluation in itself does not raise any error: if the CBORPath expression does not match the input value, the input CBOR document will be returned.

Source

pub fn write_from_bytes<'a, F>( &self, cbor: &'a [u8], map_function: F, ) -> Result<Option<Vec<u8>>, Error>
where F: FnMut(&'a [u8]) -> Result<Option<Cow<'a, [u8]>>, Error>,

Replaces or deletes the value on the given path with the result of the map_function

§Arguments
  • cbor - the CBOR input document
  • map_function - Returns a converted CBOR sub-document to replace the input CBOR sub-document or None to delete the input sub-document.
§Return

The updated CBOR document or None if the CBORPath expression does not match the input value.

The evaluation in itself does not raise any error: if the CBORPath expression does not match the input value, the input CBOR document will be returned.

Errors can only occur if the input buffer is not a valid CBOR document.

Source

pub fn set<'a>(&self, cbor: &'a Cbor, new_val: &'a Cbor) -> Option<CborOwned>

Sets the new_val this path points to in the provided cbor document

§Arguments
  • cbor - the CBOR input document
  • new_val - the CBOR sub-document to set
§Return

The updated CBOR document or None if the CBORPath expression does not match the input value.

The evaluation in itself does not raise any error: if the CBORPath expression does not match the input value, the input CBOR document will be returned.

Source

pub fn set_from_bytes<'a>( &self, cbor: &'a [u8], new_val: &'a [u8], ) -> Result<Option<Vec<u8>>, Error>

Sets the new_val this path points to in the provided cbor document

§Arguments
  • cbor - the CBOR input document
  • new_val - the CBOR sub-document to set
§Return

The updated CBOR document or None if the CBORPath expression does not match the input value.

The evaluation in itself does not raise any error: if the CBORPath expression does not match the input value, the input CBOR document will be returned.

Errors can only occur if the input buffer is not a valid CBOR document.

Source

pub fn delete(&self, cbor: &Cbor) -> Option<CborOwned>

Deletes the CBOR sub-documents this path points to in the provided cbordocument

§Arguments
  • cbor - the CBOR input document
§Return

The updated CBOR document or None if the CBORPath expression does not match the input value.

The evaluation in itself does not raise any error: if the CBORPath expression does not match the input value, the input CBOR document will be returned.

Source

pub fn delete_from_byte(&self, cbor: &[u8]) -> Result<Option<Vec<u8>>, Error>

Deletes the CBOR sub-documents this path points to in the provided cbordocument

§Arguments
  • cbor - the CBOR input document
§Return

The updated CBOR document or None if the CBORPath expression does not match the input value.

The evaluation in itself does not raise any error: if the CBORPath expression does not match the input value, the input CBOR document will be returned.

Errors can only occur if the input buffer is not a valid CBOR document.

Trait Implementations§

Source§

impl Debug for CborPath

Source§

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

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

impl PartialEq for CborPath

Source§

fn eq(&self, other: &CborPath) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&Cbor> for CborPath

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Cbor) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl StructuralPartialEq for CborPath

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.