pin_cell/
pin_ref.rs

1use core::cell::Ref;
2use core::fmt;
3use core::ops::Deref;
4use core::pin::Pin;
5
6#[derive(Debug)]
7/// A wrapper type for a immutably borrowed value from a `PinCell<T>`.
8pub struct PinRef<'a, T: ?Sized> {
9    pub(crate) inner: Pin<Ref<'a, T>>,
10}
11
12impl<'a, T: ?Sized> Deref for PinRef<'a, T> {
13    type Target = T;
14
15    fn deref(&self) -> &T {
16        &*self.inner
17    }
18}
19
20impl<'a, T: ?Sized> PinRef<'a, T> {
21    /// Get a pinned reference to the value inside this wrapper.
22    pub fn as_ref<'b>(orig: &'b PinRef<'a, T>) -> Pin<&'b T> {
23        orig.inner.as_ref()
24    }
25}
26
27/* TODO implement these APIs
28
29impl<'a, T: ?Sized> PinRef<'a, T> {
30    pub fn clone(orig: &PinRef<'a, T>) -> PinRef<'a, T> {
31        panic!()
32    }
33
34    pub fn map<U, F>(orig: PinRef<'a, T>, f: F) -> PinRef<'a, U> where
35        F: FnOnce(Pin<&T>) -> Pin<&U>,
36    {
37        panic!()
38    }
39
40    pub fn map_split<U, V, F>(orig: PinRef<'a, T>, f: F) -> (PinRef<'a, U>, PinRef<'a, V>) where
41        F: FnOnce(Pin<&T>) -> (Pin<&U>, Pin<&V>)
42    {
43        panic!()
44    }
45}
46*/
47
48impl<'a, T: fmt::Display + ?Sized> fmt::Display for PinRef<'a, T> {
49    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
50        <T as fmt::Display>::fmt(&**self, f)
51    }
52}
53
54// TODO CoerceUnsized