Skip to main content

RdiError

Enum RdiError 

Source
#[non_exhaustive]
pub enum RdiError { ServiceNotFound { ty: &'static str, context: Option<String>, }, KeyedServiceNotFound { key: String, ty: &'static str, context: Option<String>, }, CircularDependency(String), SingletonDependsOnScoped { singleton: String, scoped: String, }, FactoryPanic { service: String, payload: String, }, OwnedNotSupported(&'static str), AsyncServiceRequiresBuildAsync { service: String, }, AsyncServiceRequiresGetAsync { service: String, }, SyncSingletonDependsOnAsyncService { singleton: String, async_service: String, }, ScopedFromRootProvider { service: String, }, ProviderDisposed, ScopeDisposed, }
Expand description

Errors returned by the container.

The enum is #[non_exhaustive]: future releases may add variants without a semver-major break. Match with a wildcard arm (_ => …) when handling errors.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

ServiceNotFound

Fields

§ty: &'static str
§context: Option<String>
§

KeyedServiceNotFound

Fields

§ty: &'static str
§context: Option<String>
§

CircularDependency(String)

§

SingletonDependsOnScoped

Fields

§singleton: String
§scoped: String
§

FactoryPanic

Fields

§service: String
§payload: String
§

OwnedNotSupported(&'static str)

§

AsyncServiceRequiresBuildAsync

Fields

§service: String
§

AsyncServiceRequiresGetAsync

Fields

§service: String
§

SyncSingletonDependsOnAsyncService

同步 singleton 依赖 async singleton(build 期检测)。

同步构造函数无法 await,因此该依赖方向在架构上不成立:请把依赖方也改为 async singleton,或在方法内用 ScopeFactory / get_async 延迟解析。

Fields

§singleton: String
§async_service: String
§

ScopedFromRootProvider

严格 scope 校验下从 root provider 解析 Scoped 服务。

等价于 MEDI ValidateScopes 的 InvalidOperationException("Cannot resolve scoped service from root provider.")。

Fields

§service: String
§

ProviderDisposed

provider 已被显式 dispose 或已销毁。

§

ScopeDisposed

scope 已被显式 dispose 或 Drop 释放。

Implementations§

Source§

impl RdiError

Source

pub fn not_found(ty: &'static str, context: impl Into<Option<String>>) -> Self

Build a ServiceNotFound with an optional consumer context.

Source

pub fn keyed_not_found( ty: &'static str, key: impl Into<String>, context: impl Into<Option<String>>, ) -> Self

Build a KeyedServiceNotFound with optional context.

Source

pub fn scoped_from_root(service: &'static str) -> Self

Build a ScopedFromRootProvider for service.

Source

pub fn is_circular(&self) -> bool

Whether this error (or a wrapping FactoryPanic) represents a dependency cycle.

When a user factory unwrap()s a nested CircularDependency, the top-level build error is a FactoryPanic whose payload contains the CircularDependency rendering. This helper is a heuristic: it also matches a FactoryPanic whose (user-provided) payload happens to contain that text. Prefer matching the typed variants directly when available.

Source

pub fn from_panic_payload(service: &str, payload: Box<dyn Any + Send>) -> Self

Convert a panic::catch_unwind payload into RdiError.

Prefers a panicked RdiError (from inject constructors via panic_any), then string payloads, otherwise wraps as FactoryPanic.

Trait Implementations§

Source§

impl Clone for RdiError

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 Debug for RdiError

Source§

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

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

impl Display for RdiError

Source§

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

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

impl Error for RdiError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. 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> 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, 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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.