Enum EditTree

Source
pub enum EditTree<T> {
    MatchNode {
        pre: usize,
        suf: usize,
        left: Option<Box<EditTree<T>>>,
        right: Option<Box<EditTree<T>>>,
    },
    ReplaceNode {
        replacee: Vec<T>,
        replacement: Vec<T>,
    },
}
Expand description

Enum representing either a EditTree::MatchNode with a prefix and suffix length or a EditTree::ReplaceNode describing a replace operation.

Variants§

§

MatchNode

Fields

§pre: usize
§suf: usize
§left: Option<Box<EditTree<T>>>
§right: Option<Box<EditTree<T>>>
§

ReplaceNode

Fields

§replacee: Vec<T>
§replacement: Vec<T>

Implementations§

Source§

impl<T> EditTree<T>
where T: PartialEq + Eq + Clone,

Source

pub fn create_tree(a: &[T], b: &[T]) -> Option<Self>

Returns a edit tree specifying how to derive b from a.

Caution: when using with stringy types. UTF-8 multi byte chars will not be treated well. Consider passing in &char instead.

Source

pub fn pretty_print(&self, format_vec: impl Fn(&[T]) -> String + Copy) -> String

Returns a s-String representation of the EditTree.

format_vec defines how to transform the Vec<T> of a ReplaceNode into a String. This is useful when implementing Display for your own types where conversion to String may not be straight forward.

Trait Implementations§

Source§

impl<T: PartialEq + Eq + Clone + Debug> Apply<T> for EditTree<T>

Source§

fn apply(&self, form: &[T]) -> Option<Vec<T>>

Recursively applies the nodes stored in the edit tree. Returns None if the tree is not applicable to form.

Source§

impl<T: Clone> Clone for EditTree<T>

Source§

fn clone(&self) -> EditTree<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for EditTree<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de, T> Deserialize<'de> for EditTree<T>
where T: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for EditTree<char>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T: Hash> Hash for EditTree<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: PartialEq> PartialEq for EditTree<T>

Source§

fn eq(&self, other: &EditTree<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> Serialize for EditTree<T>
where T: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T: Eq> Eq for EditTree<T>

Source§

impl<T> StructuralPartialEq for EditTree<T>

Auto Trait Implementations§

§

impl<T> Freeze for EditTree<T>

§

impl<T> RefUnwindSafe for EditTree<T>
where T: RefUnwindSafe,

§

impl<T> Send for EditTree<T>
where T: Send,

§

impl<T> Sync for EditTree<T>
where T: Sync,

§

impl<T> Unpin for EditTree<T>
where T: Unpin,

§

impl<T> UnwindSafe for EditTree<T>
where T: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,