Debian Codegraph @

third_party/rust/fluent-fallback/src/pin_cell/pin_ref.rs

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