Skip to main content

Editor

Struct Editor 

Source
pub struct Editor<'a> { /* private fields */ }
Available on crate feature alloc only.
Expand description

Incremental editor for canonical CBOR bytes.

Implementations§

Source§

impl<'a> Editor<'a>

Source

pub fn options_mut(&mut self) -> &mut EditOptions

Returns mutable access to editor options.

Source

pub fn splice<'p>( &'p mut self, array_path: &'p [PathElem<'p>], pos: ArrayPos, delete: usize, ) -> Result<ArraySpliceBuilder<'p, 'a, 'p>, CborError>

Start building an array splice at array_path.

array_path must resolve to an array at apply time. Indices are interpreted against the original array (before edits).

§Errors

Returns CborError on invalid paths or malformed splice parameters.

Source

pub fn push<T: EditEncode<'a>>( &mut self, array_path: &[PathElem<'_>], value: T, ) -> Result<(), CborError>

Append a value to the end of an array.

§Errors

Returns CborError for invalid paths or encoding failure.

Source

pub fn push_encoded<F>( &mut self, array_path: &[PathElem<'_>], f: F, ) -> Result<(), CborError>
where F: FnOnce(&mut Encoder) -> Result<(), CborError>,

Append an encoded value to the end of an array.

§Errors

Returns CborError for invalid paths or encoding failure.

Source

pub fn set<T: EditEncode<'a>>( &mut self, path: &[PathElem<'_>], value: T, ) -> Result<(), CborError>

Set or replace the value at path.

For map keys this performs an upsert; for arrays it replaces the element.

§Errors

Returns CborError on invalid paths, conflicts, or encoding failure.

Source

pub fn insert<T: EditEncode<'a>>( &mut self, path: &[PathElem<'_>], value: T, ) -> Result<(), CborError>

Insert an entry at path.

For map keys this inserts the key. For arrays this inserts before the index.

§Errors

Returns an error if the key already exists or if the path is invalid.

Source

pub fn replace<T: EditEncode<'a>>( &mut self, path: &[PathElem<'_>], value: T, ) -> Result<(), CborError>

Replace an entry at path.

For map keys this replaces the key. For arrays this replaces the element.

§Errors

Returns an error if the key is missing or if the path is invalid.

Source

pub fn set_raw( &mut self, path: &[PathElem<'_>], value: CborValueRef<'a>, ) -> Result<(), CborError>

Set a value from an existing canonical value reference without re-encoding.

§Errors

Returns CborError on invalid paths or conflicts.

Source

pub fn set_encoded<F>( &mut self, path: &[PathElem<'_>], f: F, ) -> Result<(), CborError>
where F: FnOnce(&mut Encoder) -> Result<(), CborError>,

Encode a value using a Encoder and set it at path.

§Errors

Returns CborError if encoding fails or if the encoded bytes are not a single CBOR item.

Source

pub fn delete(&mut self, path: &[PathElem<'_>]) -> Result<(), CborError>

Delete an entry at path.

For map keys this deletes the key. For arrays this deletes the element.

§Errors

Returns an error if the key is missing or if the path is invalid.

Source

pub fn delete_if_present( &mut self, path: &[PathElem<'_>], ) -> Result<(), CborError>

Delete an entry at path if present.

For map keys this ignores missing keys. For arrays this ignores out-of-bounds indices.

§Errors

Returns an error for invalid paths or conflicts.

Source

pub fn apply(self) -> Result<CanonicalCbor, CborError>

Apply all recorded edits and return updated canonical CBOR.

§Errors

Returns an error if any edit is invalid, conflicts, or fails during encoding.

Trait Implementations§

Source§

impl<'a> Debug for Editor<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Editor<'a>

§

impl<'a> RefUnwindSafe for Editor<'a>

§

impl<'a> Send for Editor<'a>

§

impl<'a> Sync for Editor<'a>

§

impl<'a> Unpin for Editor<'a>

§

impl<'a> UnsafeUnpin for Editor<'a>

§

impl<'a> UnwindSafe for Editor<'a>

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> Same for T

Source§

type Output = T

Should always be Self
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.