pub struct TextEdit {
pub range: TextRange,
pub new_text: String,
pub safety: Safety,
}Expand description
A unified atomic edit operation.
This struct holds the data for a modification but does not execute it. It always refers to the byte offsets in the ORIGINAL source code.
Fields§
§range: TextRangeThe range in the original text to be replaced.
new_text: StringThe new text to replace the range with.
safety: SafetyHow safe this specific edit is.
Implementations§
Source§impl TextEdit
impl TextEdit
Sourcepub fn insert(offset: u32, text: impl Into<String>) -> Self
pub fn insert(offset: u32, text: impl Into<String>) -> Self
Creates an insert edit (defaults to Safe).
Sourcepub fn replace(range: impl Into<TextRange>, text: impl Into<String>) -> Self
pub fn replace(range: impl Into<TextRange>, text: impl Into<String>) -> Self
Creates a replace edit (defaults to Safe).
Sourcepub fn with_safety(self, safety: Safety) -> Self
pub fn with_safety(self, safety: Safety) -> Self
Builder method to change the safety level of this edit.
§Example
use mago_text_edit::{TextEdit, Safety};
let edit = TextEdit::replace(1..2, "b").with_safety(Safety::Unsafe);
assert_eq!(edit.safety, Safety::Unsafe);Trait Implementations§
Source§impl<'de> Deserialize<'de> for TextEdit
impl<'de> Deserialize<'de> for TextEdit
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 TextEdit
impl StructuralPartialEq for TextEdit
Auto Trait Implementations§
impl Freeze for TextEdit
impl RefUnwindSafe for TextEdit
impl Send for TextEdit
impl Sync for TextEdit
impl Unpin for TextEdit
impl UnwindSafe for TextEdit
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