pub trait FileStore: Send + Sync {
// Required methods
fn read(&self, path: &Path) -> Result<String, GettextError>;
fn write(&self, path: &Path, content: &str) -> Result<(), GettextError>;
fn modified_time(&self, path: &Path) -> Result<SystemTime, GettextError>;
fn exists(&self, path: &Path) -> bool;
// Provided method
fn write_bytes(&self, path: &Path, bytes: &[u8]) -> Result<(), GettextError> { ... }
}Expand description
File I/O contract used by crate::service::store::GettextStore.
Implementations are expected to be Send + Sync so they can be shared
behind an Arc across async tasks. Reads and writes are blocking by
design (called from spawn_blocking in the store layer).
Required Methods§
Sourcefn read(&self, path: &Path) -> Result<String, GettextError>
fn read(&self, path: &Path) -> Result<String, GettextError>
Read the file at path as a UTF-8 string. Implementations should
strip any leading UTF-8 BOM before returning.
Sourcefn write(&self, path: &Path, content: &str) -> Result<(), GettextError>
fn write(&self, path: &Path, content: &str) -> Result<(), GettextError>
Atomically write content to path. Implementations should hold
an advisory lock on the target during the write where possible.
Sourcefn modified_time(&self, path: &Path) -> Result<SystemTime, GettextError>
fn modified_time(&self, path: &Path) -> Result<SystemTime, GettextError>
Return the on-disk modified time of path, used by the store
manager to detect external edits and invalidate caches.
Provided Methods§
Sourcefn write_bytes(&self, path: &Path, bytes: &[u8]) -> Result<(), GettextError>
fn write_bytes(&self, path: &Path, bytes: &[u8]) -> Result<(), GettextError>
Atomically write a raw byte buffer to path. Used for binary
artifacts like .mo files. Default impl just routes through
FileStore::write by treating the bytes as UTF-8 — implementors
that need to honour arbitrary bytes (the production
FsFileStore) should override.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".