pub trait Codec: Send + Sync {
// Required methods
fn id(&self) -> &str;
fn diff(&self, old: &[u8], new: &[u8]) -> Result<Vec<PatchOp>, PatchError>;
fn apply(&self, base: &[u8], ops: &[PatchOp]) -> Result<Vec<u8>, PatchError>;
fn invert(&self, ops: &[PatchOp]) -> Result<Vec<PatchOp>, PatchError>;
fn commute(
&self,
left: &[PatchOp],
right: &[PatchOp],
) -> Result<(Vec<PatchOp>, Vec<PatchOp>), PatchError>;
fn merge3(
&self,
base: &[u8],
left: &[u8],
right: &[u8],
) -> Result<Vec<u8>, PatchError>;
}Expand description
A content-aware patch implementation.
Codecs define how to diff, apply, invert, commute, and three-way merge a specific content family. Implementations should return typed errors instead of panicking on malformed patch operations or invalid input bytes.
Required Methods§
Sourcefn diff(&self, old: &[u8], new: &[u8]) -> Result<Vec<PatchOp>, PatchError>
fn diff(&self, old: &[u8], new: &[u8]) -> Result<Vec<PatchOp>, PatchError>
Build patch operations that transform old bytes into new bytes.
Sourcefn apply(&self, base: &[u8], ops: &[PatchOp]) -> Result<Vec<u8>, PatchError>
fn apply(&self, base: &[u8], ops: &[PatchOp]) -> Result<Vec<u8>, PatchError>
Apply patch operations to base bytes.
Sourcefn invert(&self, ops: &[PatchOp]) -> Result<Vec<PatchOp>, PatchError>
fn invert(&self, ops: &[PatchOp]) -> Result<Vec<PatchOp>, PatchError>
Return operations that undo the provided operations.