Skip to main content

DatasourceRegistry

Struct DatasourceRegistry 

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

应用持有的全部具名数据源。

Implementations§

Source§

impl DatasourceRegistry

Source

pub fn new( default: Option<DatasourceId>, datasources: Vec<Datasource>, ) -> Result<Self, BaseError>

构造注册表。

  • default 为 None 时:只有一个源则自动成为默认源,多个源则报错;
  • 重名、默认源不存在均报错。
Source

pub fn default_id(&self) -> &DatasourceId

返回默认数据源名。

Source

pub fn default_datasource(&self) -> &Datasource

返回默认数据源。

Source

pub fn get(&self, id: &DatasourceId) -> Option<&Datasource>

按逻辑名查找数据源。

Source

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

解析可选数据源名:None 表示默认源。

Source

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

解析数据源名:字面量 default 在未注册同名源时回退到注册表的默认源。

Source

pub fn contains(&self, id: &DatasourceId) -> bool

是否包含指定数据源。

Source

pub fn len(&self) -> usize

数据源数量。

Source

pub fn is_empty(&self) -> bool

是否为空(构造期已禁止,保留 API 一致性)。

Source

pub fn iter(&self) -> impl Iterator<Item = &Datasource>

按注册顺序迭代。

Source

pub async fn health_check(&self) -> Vec<ResourceHealth>

逐源健康检查;只包含参与 readiness 的 required 源。

Source

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

逐源健康快照(带逻辑名与 required 标记)。

Source

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

逐源连接池状态。

Source

pub async fn close(&self)

按注册逆序关闭所有连接池。

Trait Implementations§

Source§

impl Debug for DatasourceRegistry

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