pin_cell/
pin_mut.rs

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