use std::{ops, pin, ptr};
use crate::base::marker::ThreadBound;
#[derive(Debug)]
#[repr(transparent)]
pub struct Occupied<'a, T> {
pub(super) value: &'a mut T,
pub(super) bound: ThreadBound,
}
impl<'a, T> Occupied<'a, T> {
pub fn get_mut(&mut self) -> &mut T {
self.value
}
pub fn into_inner(self) -> T {
let this = std::mem::ManuallyDrop::new(self);
unsafe { ptr::read(&raw const *this.value) }
}
pub fn with_pin<R>(self, run: impl for<'p> FnOnce(pin::Pin<&'p mut T>) -> R) -> R {
run(unsafe { pin::Pin::new_unchecked(&mut *self.value) })
}
}
impl<T> ops::Deref for Occupied<'_, T> {
type Target = T;
fn deref(&self) -> &T {
self.value
}
}
impl<T> Drop for Occupied<'_, T> {
fn drop(&mut self) {
unsafe { ptr::drop_in_place(self.value) };
}
}