self_reference/
refs.rs

1use core::marker::PhantomData;
2use core::pin::Pin;
3
4// Reference gateway
5pub trait RefDef {
6    type Type<'this>
7    where
8        Self: 'this;
9}
10
11pub struct Mut<T: ?Sized>(PhantomData<T>);
12impl<T: ?Sized> RefDef for Mut<T> {
13    type Type<'this> = &'this mut T where T: 'this;
14}
15
16pub struct OptionMut<T: ?Sized>(PhantomData<T>);
17impl<T: ?Sized> RefDef for OptionMut<T> {
18    type Type<'this> = Option<&'this mut T> where T: 'this;
19}
20
21pub struct Ref<T: ?Sized>(PhantomData<T>);
22impl<T: ?Sized> RefDef for Ref<T> {
23    type Type<'this> = &'this T where T: 'this;
24}
25
26pub struct OptionRef<T: ?Sized>(PhantomData<T>);
27impl<T: ?Sized> RefDef for OptionRef<T> {
28    type Type<'this> = Option<&'this T> where T: 'this;
29}
30
31pub struct PinMut<T: ?Sized>(PhantomData<T>);
32impl<T: ?Sized> RefDef for PinMut<T> {
33    type Type<'this> = Pin<&'this mut T> where T: 'this;
34}
35
36pub struct OptionPinMut<T: ?Sized>(PhantomData<T>);
37impl<T: ?Sized> RefDef for OptionPinMut<T> {
38    type Type<'this> = Option<Pin<&'this mut T>> where T: 'this;
39}
40
41pub struct PinRef<T: ?Sized>(PhantomData<T>);
42impl<T: ?Sized> RefDef for PinRef<T> {
43    type Type<'this> = Pin<&'this T> where T: 'this;
44}
45
46pub struct OptionPinRef<T: ?Sized>(PhantomData<T>);
47impl<T: ?Sized> RefDef for OptionPinRef<T> {
48    type Type<'this> = Option<Pin<&'this T>> where T: 'this;
49}