async_selector/selector/
wrappers.rs1use std::{
2 ops::{Deref, DerefMut},
3 pin::Pin,
4};
5
6use crate::{list, selector::Id};
7
8pub struct Borrowed<'a, T>(pub(super) list::Borrowed<&'a T>);
10
11impl<'a, T> Borrowed<'a, T> {
12 pub fn id(&self) -> &Id<T> {
14 Id::new(self.0.node())
15 }
16
17 pub fn get_pin(&self) -> Pin<&T> {
19 self.0.get_pin()
20 }
21
22 pub fn into_pin(self) -> Pin<&'a T> {
24 self.0.into_pin()
25 }
26}
27
28impl<C> Deref for Borrowed<'_, C> {
29 type Target = C;
30
31 fn deref(&self) -> &Self::Target {
32 self.get_pin().get_ref()
33 }
34}
35
36pub struct BorrowedMut<'a, T>(pub(super) list::Borrowed<&'a mut T>);
38
39impl<'a, T> BorrowedMut<'a, T> {
40 pub fn id(&self) -> &Id<T> {
42 Id::new(self.0.node())
43 }
44
45 pub fn get_pin(&self) -> Pin<&T> {
47 self.0.get_pin()
48 }
49
50 pub fn into_pin(self) -> Pin<&'a T> {
52 self.0.into_pin_mut().into_ref()
53 }
54
55 pub fn get_pin_mut(&mut self) -> Pin<&mut T> {
57 self.0.get_pin_mut()
58 }
59
60 pub fn into_pin_mut(self) -> Pin<&'a mut T> {
62 self.0.into_pin_mut()
63 }
64}
65
66impl<C> Deref for BorrowedMut<'_, C> {
67 type Target = C;
68
69 fn deref(&self) -> &Self::Target {
70 self.get_pin().get_ref()
71 }
72}
73
74impl<C: Unpin> DerefMut for BorrowedMut<'_, C> {
75 fn deref_mut(&mut self) -> &mut Self::Target {
76 self.get_pin_mut().get_mut()
77 }
78}
79
80pub struct Removed<T>(pub(super) list::Removed<T>);
82
83impl<T> Removed<T> {
84 pub fn id(&self) -> &Id<T> {
86 Id::new(self.0.node())
87 }
88
89 pub fn get_pin(&self) -> Pin<&T> {
91 self.0.get_pin()
92 }
93
94 pub fn get_pin_mut(&mut self) -> Pin<&mut T> {
96 self.0.get_pin_mut()
97 }
98
99 pub fn into_inner(self) -> T
104 where
105 T: Unpin,
106 {
107 self.0.into_inner()
108 }
109}
110
111impl<T> Deref for Removed<T> {
112 type Target = T;
113
114 fn deref(&self) -> &Self::Target {
115 self.get_pin().get_ref()
116 }
117}
118
119impl<T: Unpin> DerefMut for Removed<T> {
120 fn deref_mut(&mut self) -> &mut Self::Target {
121 self.get_pin_mut().get_mut()
122 }
123}