pub struct ChangeSet<T, F>{ /* private fields */ }
Expand description
A recorded set of tree modifications.
You can use ChangeSet::modify
to construct a new modified tree from an
existing one.
§Examples
use syntree::edit::ChangeSet;
let tree = syntree::tree! {
"root" => {
"child" => {
("lit", 1),
("lit", 2),
},
("whitespace", 3),
}
};
let child = tree.first().and_then(|n| n.first()).ok_or("missing child")?;
let mut change_set = ChangeSet::new();
change_set.remove(child.id());
assert_eq!(
change_set.modify(&tree)?,
syntree::tree! {
"root" => {
("whitespace", 3)
}
}
);
let lit = child.first().ok_or("missing lit")?;
let mut change_set = ChangeSet::new();
change_set.remove(lit.id());
assert_eq!(
change_set.modify(&tree)?,
syntree::tree! {
"root" => {
"child" => {
("lit", 2),
},
("whitespace", 3)
}
}
);
Implementations§
Source§impl<T, F> ChangeSet<T, F>
impl<T, F> ChangeSet<T, F>
Sourcepub fn remove(&mut self, id: F::Pointer)
pub fn remove(&mut self, id: F::Pointer)
Register a node removal in the changeset. Only one kind of modification for a given node will be preserved.
§Examples
use syntree::edit::ChangeSet;
let tree = syntree::tree! {
"root" => {
"child" => {
("lit", 1),
("lit", 2),
},
("whitespace", 3),
}
};
let child = tree.first().and_then(|n| n.first()).ok_or("missing child")?;
let mut change_set = ChangeSet::new();
change_set.remove(child.id());
assert_eq!(
change_set.modify(&tree)?,
syntree::tree! {
"root" => {
("whitespace", 3)
}
}
);
Sourcepub fn modify(
&mut self,
tree: &Tree<T, F>,
) -> Result<Tree<T, F>, Error<F::Error>>
pub fn modify( &mut self, tree: &Tree<T, F>, ) -> Result<Tree<T, F>, Error<F::Error>>
Construct a modified tree where the recorded modifications have been applied.
§Errors
Errors with Error::Overflow
in case we run out of node
identifiers.
§Examples
use syntree::edit::ChangeSet;
let tree = syntree::tree! {
"root" => {
"child" => {
("lit", 1),
("lit", 2),
},
("whitespace", 3),
}
};
let child = tree.first().and_then(|n| n.first()).ok_or("missing child")?;
let mut change_set = ChangeSet::new();
change_set.remove(child.id());
assert_eq!(
change_set.modify(&tree)?,
syntree::tree! {
"root" => {
("whitespace", 3)
}
}
);
Trait Implementations§
Auto Trait Implementations§
impl<T, F> Freeze for ChangeSet<T, F>
impl<T, F> RefUnwindSafe for ChangeSet<T, F>where
<F as Flavor>::Storage<Links<T, <F as Flavor>::Index, <F as Flavor>::Pointer>>: RefUnwindSafe,
<F as Flavor>::Indexes: RefUnwindSafe,
<F as Flavor>::Pointer: RefUnwindSafe,
<F as Flavor>::Index: RefUnwindSafe,
impl<T, F> Send for ChangeSet<T, F>
impl<T, F> Sync for ChangeSet<T, F>
impl<T, F> Unpin for ChangeSet<T, F>
impl<T, F> UnwindSafe for ChangeSet<T, F>where
<F as Flavor>::Pointer: UnwindSafe,
<F as Flavor>::Storage<Links<T, <F as Flavor>::Index, <F as Flavor>::Pointer>>: UnwindSafe,
<F as Flavor>::Indexes: UnwindSafe,
<F as Flavor>::Index: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more