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>
impl<'a> Transform<'a>
Sourcepub fn set_attr(
&mut self,
path: Vec<usize>,
key: impl Into<String>,
value: impl Into<Value>,
) -> Result<&mut Self, ApplyError>
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.
Sourcepub fn remove_attr(
&mut self,
path: Vec<usize>,
key: impl Into<String>,
) -> Result<&mut Self, ApplyError>
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.
Sourcepub fn set_text(
&mut self,
path: Vec<usize>,
text: Option<String>,
) -> Result<&mut Self, ApplyError>
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).
Sourcepub fn set_marks(
&mut self,
path: Vec<usize>,
marks: Option<Vec<Mark>>,
) -> Result<&mut Self, ApplyError>
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).
Sourcepub fn set_extra(
&mut self,
path: Vec<usize>,
key: impl Into<String>,
value: impl Into<Value>,
) -> Result<&mut Self, ApplyError>
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.
Sourcepub fn remove_extra(
&mut self,
path: Vec<usize>,
key: impl Into<String>,
) -> Result<&mut Self, ApplyError>
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.
Sourcepub fn insert(
&mut self,
path: Vec<usize>,
index: usize,
node: Node,
) -> Result<&mut Self, ApplyError>
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.
Sourcepub fn remove(
&mut self,
path: Vec<usize>,
index: usize,
) -> Result<&mut Self, ApplyError>
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).
Sourcepub fn replace(
&mut self,
path: Vec<usize>,
node: Node,
) -> Result<&mut Self, ApplyError>
pub fn replace( &mut self, path: Vec<usize>, node: Node, ) -> Result<&mut Self, ApplyError>
Replace the node at path wholesale.
Sourcepub fn move_child(
&mut self,
path: Vec<usize>,
from: usize,
to: usize,
) -> Result<&mut Self, ApplyError>
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§impl Transform<'_>
Block-structural builders. Unlike the field/child ops above (which map to a
single Change), these restructure the tree and are recorded by running
the in-place edit and recovering the patch via diff — so
they clone the tree once (only on this transaction path; the direct
Node methods stay clone-free).
impl Transform<'_>
Block-structural builders. Unlike the field/child ops above (which map to a
single Change), these restructure the tree and are recorded by running
the in-place edit and recovering the patch via diff — so
they clone the tree once (only on this transaction path; the direct
Node methods stay clone-free).
Sourcepub fn set_block_type(
&mut self,
path: Vec<usize>,
new_type: impl Into<String>,
attrs: Option<Map<String, Value>>,
) -> Result<&mut Self, BlockError>
pub fn set_block_type( &mut self, path: Vec<usize>, new_type: impl Into<String>, attrs: Option<Map<String, Value>>, ) -> Result<&mut Self, BlockError>
Record Node::set_block_type.
Sourcepub fn split_block(
&mut self,
path: Vec<usize>,
at: usize,
depth: usize,
) -> Result<&mut Self, BlockError>
pub fn split_block( &mut self, path: Vec<usize>, at: usize, depth: usize, ) -> Result<&mut Self, BlockError>
Record Node::split_block.
Sourcepub fn split_block_at(
&mut self,
path: Vec<usize>,
pos: Position,
depth: usize,
) -> Result<&mut Self, BlockError>
pub fn split_block_at( &mut self, path: Vec<usize>, pos: Position, depth: usize, ) -> Result<&mut Self, BlockError>
Record Node::split_block_at.
Sourcepub fn join_blocks(
&mut self,
parent: Vec<usize>,
index: usize,
) -> Result<&mut Self, BlockError>
pub fn join_blocks( &mut self, parent: Vec<usize>, index: usize, ) -> Result<&mut Self, BlockError>
Record Node::join_blocks.
Sourcepub fn wrap(
&mut self,
path: Vec<usize>,
wrapper_type: impl Into<String>,
attrs: Option<Map<String, Value>>,
) -> Result<&mut Self, BlockError>
pub fn wrap( &mut self, path: Vec<usize>, wrapper_type: impl Into<String>, attrs: Option<Map<String, Value>>, ) -> Result<&mut Self, BlockError>
Record Node::wrap.
Sourcepub fn wrap_range(
&mut self,
range: BlockRange,
wrapper_type: impl Into<String>,
attrs: Option<Map<String, Value>>,
) -> Result<&mut Self, BlockError>
pub fn wrap_range( &mut self, range: BlockRange, wrapper_type: impl Into<String>, attrs: Option<Map<String, Value>>, ) -> Result<&mut Self, BlockError>
Record Node::wrap_range.
Sourcepub fn lift(&mut self, path: Vec<usize>) -> Result<&mut Self, BlockError>
pub fn lift(&mut self, path: Vec<usize>) -> Result<&mut Self, BlockError>
Record Node::lift.