Skip to main content

Transform

Struct Transform 

Source
pub struct Transform<'a> { /* private fields */ }
Expand description

A mutation transaction over a Node tree: edits apply in place and are recorded as a Change log. Create with Node::transform.

Each builder returns Result<&mut Self, ApplyError> so calls chain with ?; an error (e.g. a path that doesn’t resolve) leaves the tree as mutated by the changes recorded so far.

Implementations§

Source§

impl<'a> Transform<'a>

Source

pub fn set_attr( &mut self, path: Vec<usize>, key: impl Into<String>, value: impl Into<Value>, ) -> Result<&mut Self, ApplyError>

Set (insert or overwrite) attribute key on the node at path.

Source

pub fn remove_attr( &mut self, path: Vec<usize>, key: impl Into<String>, ) -> Result<&mut Self, ApplyError>

Remove attribute key from the node at path.

Source

pub fn set_text( &mut self, path: Vec<usize>, text: Option<String>, ) -> Result<&mut Self, ApplyError>

Set the text payload of the node at path (None clears it).

Source

pub fn set_marks( &mut self, path: Vec<usize>, marks: Option<Vec<Mark>>, ) -> Result<&mut Self, ApplyError>

Replace the whole mark list of the node at path (None clears it).

Source

pub fn set_extra( &mut self, path: Vec<usize>, key: impl Into<String>, value: impl Into<Value>, ) -> Result<&mut Self, ApplyError>

Set (insert or overwrite) unknown top-level field key on the node at path.

Source

pub fn remove_extra( &mut self, path: Vec<usize>, key: impl Into<String>, ) -> Result<&mut Self, ApplyError>

Remove unknown top-level field key from the node at path.

Source

pub fn insert( &mut self, path: Vec<usize>, index: usize, node: Node, ) -> Result<&mut Self, ApplyError>

Insert node as a child of the node at path (the parent), at index.

Source

pub fn remove( &mut self, path: Vec<usize>, index: usize, ) -> Result<&mut Self, ApplyError>

Remove the child at index of the node at path (the parent).

Source

pub fn replace( &mut self, path: Vec<usize>, node: Node, ) -> Result<&mut Self, ApplyError>

Replace the node at path wholesale.

Source

pub fn move_child( &mut self, path: Vec<usize>, from: usize, to: usize, ) -> Result<&mut Self, ApplyError>

Relocate the child at from to to within the parent at path, without cloning its subtree. See Change::Move.

Source

pub fn changes(&self) -> &[Change]

The changes recorded so far, without consuming the transaction.

Source

pub fn finish(self) -> Vec<Change>

Finish the transaction, returning the recorded Change log.

Auto Trait Implementations§

§

impl<'a> Freeze for Transform<'a>

§

impl<'a> RefUnwindSafe for Transform<'a>

§

impl<'a> Send for Transform<'a>

§

impl<'a> Sync for Transform<'a>

§

impl<'a> Unpin for Transform<'a>

§

impl<'a> UnsafeUnpin for Transform<'a>

§

impl<'a> !UnwindSafe for Transform<'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, 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.