DynamicConfig

Struct DynamicConfig 

Source
pub struct DynamicConfig<T, M = RW> { /* private fields */ }
Expand description

A struct that contains a piece of configuration that can change.

Implementations§

Source§

impl<T> DynamicConfig<T, RW>

Source

pub fn add_notify( &self, f: impl Fn(&T) + IsGlobal, ) -> RegistryHandle<Box<dyn Fn(&T) + Send + Sync + 'static>>

Registers a callback to be notified when the configuration changes.

Prefer to use derive() or view().

Source§

impl<T, M> DynamicConfig<T, M>
where M: Mode,

Source

pub fn get(&self) -> T
where T: Clone,

Returns the current value.

Note: the returned value is not dynamic.

Source

pub fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R

Computes a result based on the current configuration value.

Useful when the configuration is not Copy and get() cannot be used.

Source

pub fn view_diff<U>( self: &Arc<Self>, to: impl Fn(&T) -> U + IsGlobal, ) -> Arc<DynamicConfig<U, RO>>
where T: Clone + IsGlobal, U: Clone + IsGlobal + HasDiff,

Returns a derived mode::RO dynamic configuration.

The derived configuration is updated only if the value actually changes.

Source

pub fn view<U>( self: &Arc<Self>, to: impl Fn(&T) -> U + IsGlobal, ) -> Arc<DynamicConfig<U, RO>>
where T: Clone + IsGlobal, U: Clone + IsGlobal,

Returns a derived mode::RO dynamic configuration.

Use view_diff() so the derived config doesn’t notify unless the value actually changes.

Source

pub fn zip<T2, M2>( self: &Arc<Self>, right: &Arc<DynamicConfig<T2, M2>>, ) -> Arc<DynamicConfig<(T, T2), RO>>
where T: Clone + IsGlobal, T2: Clone + IsGlobal, M2: Mode,

Source§

impl<T> DynamicConfig<T, RW>

Source

pub fn set(&self, make_new_config: impl FnOnce(&T) -> T)
where T: Clone,

Modifies the current configuration.

This will trigger all handlers registered with add_notify(), such as views or derived configurations.

Source

pub fn try_set<E>( &self, make_new_config: impl FnOnce(&T) -> Result<T, E>, ) -> Result<(), E>
where T: Clone,

Modifies the current configuration.

Same as set() but accepts a mutation that could return an error.

Source

pub fn silent_set(&self, make_new_config: impl FnOnce(&T) -> T)
where T: Clone,

Modifies the current configuration.

Same as set() but will not trigger notify.

Source

pub fn silent_try_set<E>( &self, make_new_config: impl FnOnce(&T) -> Result<T, E>, ) -> Result<(), E>
where T: Clone,

Modifies the current configuration.

Does not trigger notify and accepts a mutation that could return an error.

Source

pub fn derive<U>( self: &Arc<Self>, to: impl Fn(&T) -> U + IsGlobal, from: impl Fn(T, &U) -> Option<T> + IsGlobal, ) -> Arc<DynamicConfig<U, RW>>
where T: Clone + IsGlobal, U: Clone + IsGlobal + HasDiff,

Returns a derived piece of configuration.

Unlike view(), changes made to the derived configuration are applied back to the original configuration.

Source§

impl<T> DynamicConfig<T>

Source

pub fn if_change<U>( from: impl Fn(&T, &U) -> T + 'static, ) -> impl Fn(T, &U) -> Option<T> + 'static
where T: Eq,

Source

pub fn if_ptr_change<U>( from: impl Fn(&Arc<T>, &U) -> Arc<T> + 'static, ) -> impl Fn(Arc<T>, &U) -> Option<Arc<T>> + 'static

Trait Implementations§

Source§

impl<T: Debug, M: Mode> Debug for DynamicConfig<T, M>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T: Default, M: Default> Default for DynamicConfig<T, M>

Source§

fn default() -> DynamicConfig<T, M>

Returns the “default value” for a type. Read more
Source§

impl<'de, T: Deserialize<'de>> Deserialize<'de> for DynamicConfig<T>

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T> From<T> for DynamicConfig<T, RW>

Source§

fn from(config: T) -> Self

Converts to this type from the input type.
Source§

impl<T: Serialize> Serialize for DynamicConfig<T>

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<T, M = RW> !Freeze for DynamicConfig<T, M>

§

impl<T, M> RefUnwindSafe for DynamicConfig<T, M>
where M: RefUnwindSafe,

§

impl<T, M> Send for DynamicConfig<T, M>
where M: Send, T: Send,

§

impl<T, M> Sync for DynamicConfig<T, M>
where M: Sync, T: Send + Sync,

§

impl<T, M> Unpin for DynamicConfig<T, M>
where M: Unpin, T: Unpin,

§

impl<T, M> UnwindSafe for DynamicConfig<T, M>
where M: UnwindSafe,

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
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.
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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<C> IsGlobal for C
where C: Send + Sync + 'static,