generic_container/impls/
t_itself.rs

1use core::convert::Infallible;
2
3use crate::container_traits::{
4    Container, FragileContainer, FragileMutContainer, FragileTryContainer, FragileTryMutContainer,
5    MutContainer, TryContainer, TryMutContainer,
6};
7
8
9impl<T: ?Sized> FragileTryContainer<T> for T {
10    type Ref<'a>  = &'a T where T: 'a;
11    type RefError = Infallible;
12
13    #[inline]
14    fn new_container(t: T) -> Self where Self: Sized {
15        t
16    }
17
18    /// Infallibly get the `T`.
19    #[inline]
20    fn into_inner(self) -> Option<T> where Self: Sized {
21        Some(self)
22    }
23
24    /// Infallibly get immutable access to the `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 T {}
32
33impl<T: ?Sized> FragileContainer<T> for T {
34    /// Infallibly get immutable access to the `T`.
35    #[inline]
36    fn get_ref(&self) -> Self::Ref<'_> {
37        self
38    }
39}
40
41impl<T: ?Sized> Container<T> for T {}
42
43impl<T: ?Sized> FragileTryMutContainer<T> for T {
44    type RefMut<'a>  = &'a mut T where T: 'a;
45    type RefMutError = Infallible;
46
47    /// Infallibly get mutable access to the `T`.
48    #[inline]
49    fn try_get_mut(&mut self) -> Result<Self::RefMut<'_>, Self::RefMutError> {
50        Ok(self)
51    }
52}
53
54impl<T: ?Sized> TryMutContainer<T> for T {}
55
56impl<T: ?Sized> FragileMutContainer<T> for T {
57    /// Infallibly get mutable access to the `T`.
58    #[inline]
59    fn get_mut(&mut self) -> Self::RefMut<'_> {
60        self
61    }
62}
63
64impl<T: ?Sized> MutContainer<T> for T {}