Skip to main content

Tools

Struct Tools 

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

构建完成后冻结的应用资源。

Implementations§

Source§

impl Tools

Source

pub fn state(&self) -> ToolsState

返回当前生命周期状态。

Source

pub fn database(&self) -> Result<&AnyDatabase, BaseError>

获取默认数据源;未配置或生命周期已结束时失败。

Source

pub fn datasource(&self, id: &DatasourceId) -> Result<&Datasource, BaseError>

按逻辑名获取数据源;未配置、未注册或生命周期已结束时失败。

Source

pub fn database_named( &self, id: &DatasourceId, ) -> Result<&AnyDatabase, BaseError>

按逻辑名获取数据库容器。

Source

pub fn datasources(&self) -> Result<&DatasourceRegistry, BaseError>

返回全部具名数据源。

Source

pub fn mysql(&self) -> Result<&Database, BaseError>

获取默认数据源的 MySQL 连接池;默认源不是 MySQL 时返回 BaseError::DatabaseNotInitialized。

Source

pub fn pool_status(&self) -> Option<PoolStatus>

返回默认数据源的连接池状态快照;未配置数据库时为 None。

不检查生命周期状态,便于关闭后继续观察连接池回收情况。

Source

pub fn pool_statuses(&self) -> Vec<DatasourcePoolStatus>

返回全部数据源的连接池状态快照。

Source

pub async fn datasource_health(&self) -> Vec<DatasourceHealth>

返回全部数据源的健康快照。

Source

pub fn cache(&self) -> Result<&RedisClient, BaseError>

获取 Redis 客户端;未配置或生命周期已结束时失败。

Source

pub fn token(&self) -> Result<&TokenManager, BaseError>

获取 Token 管理器;未配置或生命周期已结束时失败。

Source

pub fn http(&self) -> Result<&HttpClient, BaseError>

获取 HTTP 客户端;未配置或生命周期已结束时失败。

reqwest 客户端无需显式关闭,故该槽位不参与 close/health_check 流程。

Source

pub fn regex_cache(&self) -> &RegexCache

获取共享的有界正则缓存。

缓存为冻结的不可变资源,无需参与 close/health_check 流程;始终可用。

Source

pub fn extension<T>(&self) -> Result<&T, BaseError>
where T: Any + Send + Sync,

按具体类型获取低频扩展。

Source

pub fn config<T>(&self) -> Result<&T, BaseError>
where T: Any + Send + Sync,

按具体类型获取只读配置。

Source

pub async fn health_check(&self) -> ToolsHealth

检查所有已配置核心资源并返回稳定快照。

Source

pub async fn close(&self)

幂等关闭所有核心资源。

关闭顺序与常见启动顺序相反:先 Redis,再数据库。并发调用会等待首个关闭流程完成。

Trait Implementations§

Source§

impl Debug for Tools

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Tools

§

impl !RefUnwindSafe for Tools

§

impl !UnwindSafe for Tools

§

impl Forget for Tools

§

impl Move for Tools

§

impl Send for Tools

§

impl Sync for Tools

§

impl Unpin for Tools

§

impl UnsafeUnpin for Tools

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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 = !

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