Skip to main content

LoaderFile

Struct LoaderFile 

Source
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

Source

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.

Source

pub fn path(&self) -> &Path

The file path.

Source

pub fn format(&self) -> FileFormat

The detected format.

Source

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.

Source

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.

Source

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.

Source

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

Source

pub fn last_deferred_error(&self) -> Option<String>

The last deferred-write error, if the flusher failed.

Source

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.

Source

pub fn is_suspended(&self) -> bool

Whether any suspend guard is currently held for this file.

Trait Implementations§

Source§

impl Clone for LoaderFile

Source§

fn clone(&self) -> LoaderFile

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LoaderFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.