1use crate::MiwaError;
2
3use super::{FromMiwaContext, MiwaContext, MiwaId, MiwaResult};
4
5pub struct Dep<T>(pub T);
6
7impl<T: Clone + 'static> FromMiwaContext<'_> for Dep<T> {
8 fn from_context(context: &MiwaContext) -> MiwaResult<Self> {
9 let dep = context.resolve::<T>().ok_or_else(|| {
10 MiwaError::ComponentMissing(format!(
11 "Failed to resolve dependency: {}",
12 std::any::type_name::<T>()
13 ))
14 })?;
15 Ok(Dep(dep))
16 }
17}
18
19impl<T: 'static> MiwaId for Dep<T> {
20 fn component_id() -> std::any::TypeId {
21 std::any::TypeId::of::<T>()
22 }
23}