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
impl CborPath
sourcepub fn builder() -> PathBuilder
pub fn builder() -> PathBuilder
sourcepub fn from_bytes(cbor: &[u8]) -> Result<Self, Error>
pub fn from_bytes(cbor: &[u8]) -> Result<Self, Error>
sourcepub fn from_value(cbor: &Cbor) -> Result<Self, Error>
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.
sourcepub fn read<'a>(&self, cbor: &'a Cbor) -> Vec<&'a Cbor> ⓘ
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.
sourcepub fn read_from_bytes(&self, cbor: &[u8]) -> Result<Vec<u8>, Error>
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.
sourcepub fn get_paths_from_bytes(&self, cbor: &[u8]) -> Result<Vec<Path>, Error>
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.
sourcepub 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>,
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 documentmap_function- Returns a converted CBOR sub-document to replace the input CBOR sub-document orNoneto 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.
sourcepub 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>,
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 documentmap_function- Returns a converted CBOR sub-document to replace the input CBOR sub-document orNoneto 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.
sourcepub fn set<'a>(&self, cbor: &'a Cbor, new_val: &'a Cbor) -> Option<CborOwned>
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 documentnew_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.
sourcepub fn set_from_bytes<'a>(
&self,
cbor: &'a [u8],
new_val: &'a [u8]
) -> Result<Option<Vec<u8>>, Error>
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 documentnew_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.
sourcepub fn delete(&self, cbor: &Cbor) -> Option<CborOwned>
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.
sourcepub fn delete_from_byte(&self, cbor: &[u8]) -> Result<Option<Vec<u8>>, Error>
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.