#[derive(Injectable)]Expand description
Derives an implementation of the injectium::Injectable trait.
When applied to a named struct, this macro generates:
- An implementation of
from_container(&Container) -> Selfthat resolves each field from the container usingcontainer.get::<T>(). - An implementation of
try_from_container(&Container) -> Option<Self>that usescontainer.try_get::<T>()for graceful missing-dependency handling. - A
injectium::declare_dependency!call for each field type, enablingContainer::validateto check all dependencies at startup.
§Requirements
- The struct must be a named struct (not a tuple struct or enum).
- All field types must be
'static.
§Example
ⓘ
use injectium::Injectable;
use std::sync::Arc;
#[derive(Clone)]
struct Database {
conn: Arc<Connection>,
}
#[derive(Injectable)]
struct Service {
db: Database,
}