pub struct Edit {
pub range: Range,
pub kind: EditKind,
}Expand description
A single buffer mutation: replace the bytes in Self::range with the
text carried by Self::kind.
Coordinates are pre-edit Positions (line + UTF-8 byte). A compound
change is a sequence of Edits applied in order — each against the buffer
as the previous one left it — and grouped into one undo step by the
dispatcher.
§Examples
use lattice_protocol::{Edit, EditKind, Position, Range};
// Insert "fn " at the start of line 3: an empty range plus text.
let insert = Edit::insert(Position::new(3, 0), "fn ");
assert!(insert.range.is_empty());
// Delete bytes 4..7 of line 0: a range plus empty text.
let delete = Edit::delete(Range::new(Position::new(0, 4), Position::new(0, 7)));
let EditKind::Replace { text } = &delete.kind;
assert!(text.is_empty());
// Replace is the general form both of the above reduce to.
let word = Range::new(Position::new(1, 0), Position::new(1, 5));
assert_eq!(Edit::replace(word, "world").range, word);Fields§
§range: RangeThe half-open span to replace, in pre-edit coordinates. Empty for an insert.
kind: EditKindWhat to put there.
Implementations§
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Edit
impl<'de> Deserialize<'de> for Edit
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Edit
impl StructuralPartialEq for Edit
Auto Trait Implementations§
impl Freeze for Edit
impl RefUnwindSafe for Edit
impl Send for Edit
impl Sync for Edit
impl Unpin for Edit
impl UnsafeUnpin for Edit
impl UnwindSafe for Edit
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.