#[derive(Debug)]
pub struct PersistOnDrop<'a>(*mut c_void, PhantomData<&'a DirectlyAccessibleFileBackedMemory>);
impl<'a> Drop for PersistOnDrop<'a>
{
#[inline(always)]
fn drop(&mut self)
{
DirectlyAccessibleFileBackedMemory::drainAfterFlush()
}
}
impl<'a> PersistOnDrop<'a>
{
#[inline(always)]
pub fn offset(mut self, offset: usize) -> Self
{
self.0 = unsafe { self.0.offset(offset as isize) };
self
}
#[inline(always)]
pub fn flush(&self, length: usize)
{
self.0.flush(length);
}
#[inline(always)]
pub fn copy_then_flush(&self, length: usize, from: *const c_void)
{
debug_assert!(!from.is_null(), "from must not be null");
unsafe { pmem_memmove_nodrain(self.0, from, length) };
}
#[inline(always)]
pub fn copy_nonoverlapping_then_flush(&self, length: usize, from: *const c_void)
{
debug_assert!(!from.is_null(), "from must not be null");
unsafe { pmem_memcpy_nodrain(self.0, from, length) };
}
#[inline(always)]
pub fn write_bytes_then_flush(&self, count: usize, value: u8)
{
unsafe { pmem_memset_nodrain(self.0, value as i32, count) };
}
}