Skip to main content

Codec

Trait Codec 

Source
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§

Source

fn id(&self) -> &str

Stable codec identifier stored on patch objects.

Source

fn diff(&self, old: &[u8], new: &[u8]) -> Result<Vec<PatchOp>, PatchError>

Build patch operations that transform old bytes into new bytes.

Source

fn apply(&self, base: &[u8], ops: &[PatchOp]) -> Result<Vec<u8>, PatchError>

Apply patch operations to base bytes.

Source

fn invert(&self, ops: &[PatchOp]) -> Result<Vec<PatchOp>, PatchError>

Return operations that undo the provided operations.

Source

fn commute( &self, left: &[PatchOp], right: &[PatchOp], ) -> Result<(Vec<PatchOp>, Vec<PatchOp>), PatchError>

Reorder non-conflicting operations so left and right can be applied in either order.

Source

fn merge3( &self, base: &[u8], left: &[u8], right: &[u8], ) -> Result<Vec<u8>, PatchError>

Merge independently edited byte streams against a common base.

Implementors§