/
germanubis
/
rust-postgres
Обзор
Документация
Войти
/
germanubis
/
rust-postgres
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
postgres/src/lazy_pin.rs
28 строк
541 B
Steven Fackler
Blocking binary copy support
16 дек 2019, 04:01
16 дек 2019, 04:01
a254e6e
Код
Авторство
О чём код?
use std::pin::Pin; pub(crate) struct LazyPin<T> { value: Box<T>, pinned: bool, } impl<T> LazyPin<T> { pub fn new(value: T) -> LazyPin<T> { LazyPin { value: Box::new(value), pinned: false, } } pub fn pinned(&mut self) -> Pin<&mut T> { self.pinned = true; unsafe { Pin::new_unchecked(&mut *self.value) } } pub fn into_unpinned(self) -> Option<T> { if self.pinned { None } else { Some(*self.value) } } }