postgres/lazy_pin.rs
1use std::pin::Pin;
2
3pub(crate) struct LazyPin<T> {
4 value: Box<T>,
5 pinned: bool,
6}
7
8impl<T> LazyPin<T> {
9 pub fn new(value: T) -> LazyPin<T> {
10 LazyPin {
11 value: Box::new(value),
12 pinned: false,
13 }
14 }
15
16 pub fn pinned(&mut self) -> Pin<&mut T> {
17 self.pinned = true;
18 unsafe { Pin::new_unchecked(&mut *self.value) }
19 }
20
21 pub fn into_unpinned(self) -> Option<T> {
22 if self.pinned {
23 None
24 } else {
25 Some(*self.value)
26 }
27 }
28}