Skip to main content

DocumentBackend

Trait DocumentBackend 

Source
pub trait DocumentBackend {
    // Required methods
    fn format_of(&self, path: &str) -> &'static str;
    fn read(&self, path: &str) -> Result<RawDocument, String>;
    fn write(
        &self,
        path: &str,
        content: &str,
        encoding: &str,
        expected_source_sha256: Option<&str>,
    ) -> Result<WriteDocumentResult, String>;
    fn write_bytes(
        &self,
        path: &str,
        content_base64: &str,
    ) -> Result<(), String>;
    fn write_raw_bytes(&self, path: &str, bytes: &[u8]) -> Result<(), String>;
    fn copy_document(&self, source: &str, target: &str) -> Result<(), String>;
    fn fingerprint(&self, path: &str) -> Result<FileFingerprint, String>;
}
Expand description

Document format classification and file IO as the host implements them. Errors are plain strings; the workspace classifies them into crate::WorkspaceError variants.

Required Methods§

Source

fn format_of(&self, path: &str) -> &'static str

The format id of a path ("image", "pdf", "md", …, or "unknown").

Source

fn read(&self, path: &str) -> Result<RawDocument, String>

Read and decode a document.

Source

fn write( &self, path: &str, content: &str, encoding: &str, expected_source_sha256: Option<&str>, ) -> Result<WriteDocumentResult, String>

Encode and atomically write text, rejecting stale in-place saves.

Source

fn write_bytes(&self, path: &str, content_base64: &str) -> Result<(), String>

Write base64 content as raw bytes.

Source

fn write_raw_bytes(&self, path: &str, bytes: &[u8]) -> Result<(), String>

Write raw bytes.

Source

fn copy_document(&self, source: &str, target: &str) -> Result<(), String>

Copy a document to a new location.

Source

fn fingerprint(&self, path: &str) -> Result<FileFingerprint, String>

Metadata-only fingerprint.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§