syntree::edit

Struct ChangeSet

Source
pub struct ChangeSet<T, F>
where T: Copy, F: Flavor,
{ /* 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>
where T: Copy, F: Flavor,

Source

pub fn new() -> Self

Construct a new empty ChangeSet.

Source§

impl<T, F> ChangeSet<T, F>
where T: Copy, F: Flavor,

Source

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)
        }
    }
);
Source

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§

Source§

impl<T, F> Default for ChangeSet<T, F>
where T: Copy, F: Flavor,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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>
where <F as Flavor>::Pointer: Send, <F as Flavor>::Storage<Links<T, <F as Flavor>::Index, <F as Flavor>::Pointer>>: Send, <F as Flavor>::Indexes: Send, <F as Flavor>::Index: Send,

§

impl<T, F> Sync for ChangeSet<T, F>
where <F as Flavor>::Pointer: Sync, <F as Flavor>::Storage<Links<T, <F as Flavor>::Index, <F as Flavor>::Pointer>>: Sync, <F as Flavor>::Indexes: Sync, <F as Flavor>::Index: Sync,

§

impl<T, F> Unpin for ChangeSet<T, F>
where <F as Flavor>::Storage<Links<T, <F as Flavor>::Index, <F as Flavor>::Pointer>>: Unpin, <F as Flavor>::Indexes: Unpin, <F as Flavor>::Pointer: Unpin, <F as Flavor>::Index: Unpin,

§

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> 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.