Skip to main content

ConfigHandle

Struct ConfigHandle 

Source
pub struct ConfigHandle<T> { /* private fields */ }
Expand description

Live, cloneable handle to a loaded config value.

Reads are lock-free via ArcSwap. Writes go through WriteGuard, which atomically updates the in-memory state on drop and optionally persists to the config file (watcher mode only).

Clone the handle freely — all clones share the same live value.

Implementations§

Source§

impl<T: ConfigSchema> ConfigHandle<T>

Source

pub fn read(&self) -> Guard<Arc<T>>

Lock-free snapshot of the current config. Equivalent to Arc::clone cost.

Source§

impl<T: ConfigSchema + Clone + Serialize> ConfigHandle<T>

Source

pub fn write_back( initial: T, path: impl Into<PathBuf>, format: impl Format + Send + Sync + 'static, ) -> Self

Write-back mode: no file watcher, but every WriteGuard drop persists to path.

Use this when you want config.write() to auto-save without spinning up a hot-reload thread.

Source

pub fn write(&self) -> WriteGuard<T>

Return a write guard. On drop the guard:

  1. Serializes the modified value and writes it to the config file (watcher mode).
  2. Atomically swaps it into the ArcSwap so all readers see the new value.

In manual mode only step 2 happens (no file path is stored).

Trait Implementations§

Source§

impl<T> Clone for ConfigHandle<T>

Source§

fn clone(&self) -> Self

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<T: ConfigSchema> From<T> for ConfigHandle<T>

Source§

fn from(config: T) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for ConfigHandle<T>

§

impl<T> !UnwindSafe for ConfigHandle<T>

§

impl<T> Freeze for ConfigHandle<T>
where Arc<ArcSwapAny<Arc<T>>>: Freeze,

§

impl<T> Send for ConfigHandle<T>
where Arc<ArcSwapAny<Arc<T>>>: Send,

§

impl<T> Sync for ConfigHandle<T>
where Arc<ArcSwapAny<Arc<T>>>: Sync,

§

impl<T> Unpin for ConfigHandle<T>
where Arc<ArcSwapAny<Arc<T>>>: Unpin,

§

impl<T> UnsafeUnpin for ConfigHandle<T>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more