abstract_ref/
types.rs

1use std::{borrow::BorrowMut, marker::PhantomData};
2
3pub struct Cow<'a>(PhantomData<&'a ()>);
4impl<'a, T> crate::Type<T> for Cow<'a>
5where
6    T: ?Sized + ToOwned + 'a,
7{
8    type RefT = std::borrow::Cow<'a, T>;
9}
10impl<'a, T> crate::MakeMutType<T> for Cow<'a>
11where
12    T: ?Sized + ToOwned + 'a,
13    T::Owned: BorrowMut<T>,
14{
15    fn make_mut(p: &mut Self::RefT) -> &mut T {
16        p.to_mut().borrow_mut()
17    }
18}
19
20pub struct Rc;
21impl<T: ?Sized> crate::Type<T> for Rc {
22    type RefT = std::rc::Rc<T>;
23}
24impl<T: ?Sized + Clone> crate::MakeMutType<T> for Rc {
25    fn make_mut(p: &mut Self::RefT) -> &mut T {
26        std::rc::Rc::make_mut(p)
27    }
28}
29
30pub struct Arc;
31impl<T: ?Sized> crate::Type<T> for Arc {
32    type RefT = std::sync::Arc<T>;
33}
34impl<T: ?Sized + Clone> crate::MakeMutType<T> for Arc {
35    fn make_mut(p: &mut Self::RefT) -> &mut T {
36        std::sync::Arc::make_mut(p)
37    }
38}
39
40pub struct Box;
41impl<T: ?Sized> crate::Type<T> for Box {
42    type RefT = std::boxed::Box<T>;
43}
44impl<T: ?Sized> crate::MakeMutType<T> for Box {
45    fn make_mut(p: &mut Self::RefT) -> &mut T {
46        &mut *p
47    }
48}
49
50pub type Own = ();
51impl<T> crate::Type<T> for () {
52    type RefT = T;
53}
54impl<T> crate::MakeMutType<T> for () {
55    fn make_mut(p: &mut Self::RefT) -> &mut T {
56        p
57    }
58}
59
60pub struct Brw<'a>(PhantomData<&'a ()>);
61impl<'a, T: ?Sized + 'a> crate::Type<T> for Brw<'a> {
62    type RefT = &'a T;
63}
64
65pub struct BrwMut<'a>(PhantomData<&'a ()>);
66impl<'a, T: ?Sized + 'a> crate::Type<T> for BrwMut<'a> {
67    type RefT = &'a mut T;
68}
69impl<'a, T: ?Sized + 'a> crate::MakeMutType<T> for BrwMut<'a> {
70    fn make_mut(p: &mut Self::RefT) -> &mut T {
71        p
72    }
73}