pub struct Singleton;
pub struct PerExecution;
pub struct Transient;
pub struct Auto;
mod sealed {
pub trait Sealed {}
impl Sealed for super::Singleton {}
impl Sealed for super::PerExecution {}
impl Sealed for super::Transient {}
impl Sealed for super::Auto {}
}
pub trait Scope: sealed::Sealed + 'static {
const KIND: ScopeKind;
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum ScopeKind {
Singleton,
PerExecution,
Transient,
Auto,
}
impl Scope for Singleton {
const KIND: ScopeKind = ScopeKind::Singleton;
}
impl Scope for PerExecution {
const KIND: ScopeKind = ScopeKind::PerExecution;
}
impl Scope for Transient {
const KIND: ScopeKind = ScopeKind::Transient;
}
impl Scope for Auto {
const KIND: ScopeKind = ScopeKind::Auto;
}
#[diagnostic::on_unimplemented(
message = "lifecycle hooks are only allowed on singletons",
label = "`{Self}` scope cannot have hooks",
note = "remove the scope argument from #[injectable], or move the hook to a singleton"
)]
pub trait HookCapable: Scope {}
impl HookCapable for Singleton {}
impl HookCapable for Auto {}
#[diagnostic::on_unimplemented(
message = "`{Self}` is not an explicit scope",
label = "name `Singleton`, `PerExecution` or `Transient` here",
note = "`Auto` is the default: write `guard_with`, `interceptor_with` or `error_handler_with` without a scope"
)]
pub trait ExplicitScope: Scope {}
impl ExplicitScope for Singleton {}
impl ExplicitScope for PerExecution {}
impl ExplicitScope for Transient {}
#[diagnostic::on_unimplemented(
message = "a `{S}` type cannot read `{Self}`",
label = "this injection point needs an execution",
note = "declare the type #[injectable(execution)] or #[injectable(transient)]"
)]
pub trait AllowedIn<S: Scope> {}