use crate::{Mut, Ref}; use std::{any::Any, borrow::Borrow, marker::PhantomData, ops::Deref}; /// Represents a holder for a keyed service. #[derive(Debug)] pub struct KeyedRef { service: Ref, _key: PhantomData, } /// Represents a holder for a keyed, mutable service. pub type KeyedRefMut = KeyedRef>; impl KeyedRef { /// Initializes a new holder for the specified keyed service. /// /// * `service` - The keyed service reference the holder is for pub fn new(service: Ref) -> Self { Self { service, _key: PhantomData, } } } impl Clone for KeyedRef { fn clone(&self) -> Self { Self { service: self.service.clone(), _key: PhantomData, } } } impl From> for Ref { fn from(value: KeyedRef) -> Self { value.service } } impl AsRef for KeyedRef { fn as_ref(&self) -> &TSvc { self.service.as_ref() } } impl Borrow for KeyedRef { fn borrow(&self) -> &TSvc { self.service.borrow() } } impl Deref for KeyedRef { type Target = TSvc; fn deref(&self) -> &Self::Target { self.service.deref() } }