#[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
ServiceNotFound
KeyedServiceNotFound
CircularDependency(String)
SingletonDependsOnScoped
FactoryPanic
OwnedNotSupported(&'static str)
AsyncServiceRequiresBuildAsync
AsyncServiceRequiresGetAsync
SyncSingletonDependsOnAsyncService
同步 singleton 依赖 async singleton(build 期检测)。
同步构造函数无法 await,因此该依赖方向在架构上不成立:请把依赖方也改为
async singleton,或在方法内用 ScopeFactory / get_async 延迟解析。
ScopedFromRootProvider
严格 scope 校验下从 root provider 解析 Scoped 服务。
等价于 MEDI ValidateScopes 的
InvalidOperationException("Cannot resolve scoped service from root provider.")。
ProviderDisposed
provider 已被显式 dispose 或已销毁。
ScopeDisposed
scope 已被显式 dispose 或 Drop 释放。
Implementations§
Source§impl RdiError
impl RdiError
Sourcepub fn not_found(ty: &'static str, context: impl Into<Option<String>>) -> Self
pub fn not_found(ty: &'static str, context: impl Into<Option<String>>) -> Self
Build a ServiceNotFound with an optional consumer context.
Sourcepub fn keyed_not_found(
ty: &'static str,
key: impl Into<String>,
context: impl Into<Option<String>>,
) -> Self
pub fn keyed_not_found( ty: &'static str, key: impl Into<String>, context: impl Into<Option<String>>, ) -> Self
Build a KeyedServiceNotFound with optional context.
Sourcepub fn scoped_from_root(service: &'static str) -> Self
pub fn scoped_from_root(service: &'static str) -> Self
Build a ScopedFromRootProvider for service.
Sourcepub fn is_circular(&self) -> bool
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.
Sourcepub fn from_panic_payload(service: &str, payload: Box<dyn Any + Send>) -> Self
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 Error for RdiError
impl Error for RdiError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()