Struct cborpath::CborPath

source ·
pub struct CborPath(_);
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<CborPath> for CborPath

source§

fn eq(&self, other: &CborPath) -> 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 TryFrom<&Cbor> for CborPath

§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · 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.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.