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