Skip to main content

RefreshScope

Struct RefreshScope 

Source
pub struct RefreshScope { /* private fields */ }
Expand description

RefreshScope — marks beans that should be refreshed when config changes. RefreshScope — 标记在配置更改时应刷新的 bean。

Equivalent to Spring Cloud’s @RefreshScope. 等价于 Spring Cloud 的 @RefreshScope

Manages refreshable values and fires events when configuration changes. 管理可刷新值,并在配置更改时触发事件。

Implementations§

Source§

impl RefreshScope

Source

pub fn new() -> Self

Create a new empty RefreshScope / 创建新的空 RefreshScope

Source

pub fn register(&self, key: impl Into<String>, initial_value: impl Into<String>)

Register a refreshable value / 注册可刷新值

Source

pub fn get(&self, key: &str) -> Option<String>

Get the current value of a refreshable / 获取可刷新值的当前值

Source

pub fn add_listener( &self, listener: impl Fn(&ConfigChangeEvent) + Send + Sync + 'static, )

Add a change listener / 添加变更监听器

Source

pub fn fire_event(&self, event: &ConfigChangeEvent)

Fire a config change event and update the registered refreshables. 触发配置变更事件并更新已注册的可刷新值。

This method updates the refreshable value if registered, and notifies all registered listeners. 此方法更新已注册的可刷新值,并通知所有已注册的监听器。

Source

pub fn refresh_all(&self, getter: impl Fn(&str) -> Option<String>)

Refresh all registered values with a provided getter function. 使用提供的 getter 函数刷新所有已注册的值。

The getter is called for each registered key to obtain the new value. 对每个已注册的键调用 getter 以获取新值。

Source

pub fn len(&self) -> usize

Get the number of registered refreshables / 获取已注册的可刷新值数量

Source

pub fn is_empty(&self) -> bool

Check if there are no refreshables / 检查是否没有可刷新值

Trait Implementations§

Source§

impl Debug for RefreshScope

Source§

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

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

impl Default for RefreshScope

Source§

fn default() -> Self

Returns the “default value” for a type. 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<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> 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, 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<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