pub struct LoaderFile { /* private fields */ }Expand description
A handle to one config file on disk.
Handles are cheap to clone and share path, format, and suspend state, so
several trees (or the loader and the watcher) can coordinate writes
through the same file. While any FileSuspendGuard is held,
LoaderFile::write is a silent no-op — the file-level half of breaking
the write → watch → write feedback loop.
Implementations§
Source§impl LoaderFile
impl LoaderFile
Sourcepub fn open(path: impl Into<PathBuf>) -> Result<Self>
pub fn open(path: impl Into<PathBuf>) -> Result<Self>
Open a .yml, .yaml, or .json config file. The file does not
have to exist yet; LoaderFile::read returns an empty document
until the first write creates it.
Sourcepub fn format(&self) -> FileFormat
pub fn format(&self) -> FileFormat
The detected format.
Sourcepub fn read(&self) -> Result<Document>
pub fn read(&self) -> Result<Document>
Read and parse the file. Missing and empty files yield an empty
document; ${{ ... }} templates are not expanded here — entries
keep their raw config.
Sourcepub fn write(&self, document: &Document) -> Result<()>
pub fn write(&self, document: &Document) -> Result<()>
Serialize the document and replace the file atomically (write to a
sibling .tmp file, fsync, rename). A no-op while suspended.
Sourcepub fn write_deferred(&self, document: Document, delay: Duration)
pub fn write_deferred(&self, document: Document, delay: Duration)
Schedule a coalesced write: rapid calls replace the pending document
(latest wins), and the physical write happens once delay has passed
without a newer call. A suspension active at flush time postpones the
write until it lifts. Errors surface through
LoaderFile::last_deferred_error and never propagate to callers.
If the flusher thread cannot be spawned, the write happens synchronously instead.
Sourcepub fn flush_deferred(&self)
pub fn flush_deferred(&self)
Block until every LoaderFile::write_deferred call made before
this one has been flushed (or skipped by suspension lifting and a
later flush).
Sourcepub fn last_deferred_error(&self) -> Option<String>
pub fn last_deferred_error(&self) -> Option<String>
The last deferred-write error, if the flusher failed.
Sourcepub fn suspend(&self) -> FileSuspendGuard
pub fn suspend(&self) -> FileSuspendGuard
Increment the suspend counter, returning a guard whose drop resumes writes. Hold this while reloading a file so the resulting tree patches are not written back.
Sourcepub fn is_suspended(&self) -> bool
pub fn is_suspended(&self) -> bool
Whether any suspend guard is currently held for this file.
Trait Implementations§
Source§impl Clone for LoaderFile
impl Clone for LoaderFile
Source§fn clone(&self) -> LoaderFile
fn clone(&self) -> LoaderFile
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more