generic_container/impls/
arc.rs

1use core::convert::Infallible;
2use alloc::sync::Arc;
3
4use crate::container_traits::{Container, FragileContainer, FragileTryContainer, TryContainer};
5
6
7impl<T: ?Sized> FragileTryContainer<T> for Arc<T> {
8    type Ref<'a>  = &'a T where T: 'a;
9    type RefError = Infallible;
10
11    #[inline]
12    fn new_container(t: T) -> Self where T: Sized {
13        Self::new(t)
14    }
15
16    /// Attempt to retrieve the inner `T` from the container.
17    ///
18    /// Uses [`Arc::into_inner`].
19    #[inline]
20    fn into_inner(self) -> Option<T> where T: Sized {
21        Self::into_inner(self)
22    }
23
24    /// Infallibly get immutable access to the inner `T`.
25    #[inline]
26    fn try_get_ref(&self) -> Result<Self::Ref<'_>, Self::RefError> {
27        Ok(self)
28    }
29}
30
31impl<T: ?Sized> TryContainer<T> for Arc<T> {}
32
33impl<T: ?Sized> FragileContainer<T> for Arc<T> {
34    /// Infallibly get immutable access to the inner `T`.
35    #[inline]
36    fn get_ref(&self) -> Self::Ref<'_> {
37        self
38    }
39}
40
41impl<T: ?Sized> Container<T> for Arc<T> {}