pub enum PatchOp {
Insert {
offset: usize,
content: String,
},
Delete {
offset: usize,
len: usize,
expected: Option<String>,
},
Replace {
offset: usize,
len: usize,
content: String,
expected: Option<String>,
},
InsertLine {
line: usize,
content: String,
},
DeleteLine {
line: usize,
expected: Option<String>,
},
ReplaceLine {
line: usize,
content: String,
expected: Option<String>,
},
Append {
content: String,
},
}Expand description
Generic patch operation for file modifications.
Maps to POSIX operations, CRDTs, or REST APIs. All positional ops
support compare-and-set (CAS) via optional expected field.
If expected is Some, the operation fails with ConflictError if the
current content at that position doesn’t match.
§Line Ending Normalization
Line-based operations (InsertLine, DeleteLine, ReplaceLine) normalize
line endings to Unix-style (\n). Files with \r\n (Windows) line endings
will be converted to \n after a line-based patch. This is intentional for
kaish’s Unix-first design. Use byte-based operations (Insert, Delete,
Replace) to preserve original line endings.
Variants§
Insert
Insert content at byte offset.
Delete
Delete bytes from offset to offset+len.
expected: if Some, must match content being deleted (CAS)
Replace
Replace content at offset.
expected: if Some, must match content being replaced (CAS)
InsertLine
Insert a line at line number (1-indexed).
DeleteLine
Delete a line at line number (1-indexed).
expected: if Some, must match line being deleted (CAS)
ReplaceLine
Replace a line at line number (1-indexed).
expected: if Some, must match line being replaced (CAS)
Append
Append content to end of file (no CAS needed - always safe).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PatchOp
impl RefUnwindSafe for PatchOp
impl Send for PatchOp
impl Sync for PatchOp
impl Unpin for PatchOp
impl UnwindSafe for PatchOp
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more