Skip to main content

FormatPackage

Trait FormatPackage 

Source
pub trait FormatPackage: Send + Sync {
    // Required methods
    fn id(&self) -> PackageId;
    fn detect(&self, path: &str, bytes: &[u8]) -> Option<Confidence>;
    fn project(&self, bytes: &[u8]) -> Result<Projection, PackageError>;

    // Provided method
    fn diff(
        &self,
        _before: &[u8],
        _after: &[u8],
    ) -> Option<Result<Vec<Delta>, PackageError>> { ... }
}
Expand description

One format’s support, shipped as its own versioned unit: the ecosystem’s public ABI (ADR-0003).

A package never gates a diff — when it is absent or fails, fidelity drops to the text or binary rung instead. Determinism is contract: the same bytes under the same package version must produce the same projection and the same diff. Send + Sync is part of the ABI: a workspace crosses threads (a watcher, a server), so its packages must too.

Required Methods§

Source

fn id(&self) -> PackageId

The package’s stable identity.

Source

fn detect(&self, path: &str, bytes: &[u8]) -> Option<Confidence>

How confidently this package claims the document at path with these bytes; None when it does not handle the document.

Source

fn project(&self, bytes: &[u8]) -> Result<Projection, PackageError>

Render the document to its text projection.

Provided Methods§

Source

fn diff( &self, _before: &[u8], _after: &[u8], ) -> Option<Result<Vec<Delta>, PackageError>>

The rich diff in the format’s own terms, or None while the package ships no differ — the ladder then falls back to projected text.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§