pub struct PersistentFileMapped<T> { /* private fields */ }Expand description
A FileMapped region that does not wipe pre-existing file
contents when doublets grows it.
See the module documentation for the upstream behaviour this works around.
Implementations§
Source§impl<T> PersistentFileMapped<T>
impl<T> PersistentFileMapped<T>
Sourcepub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self>
Opens (creating it if needed) the file at path and maps it.
Sourcepub fn inner(&self) -> &FileMapped<T>
pub fn inner(&self) -> &FileMapped<T>
Borrows the wrapped FileMapped.
Sourcepub fn flush_handle(&self) -> MappedFlush
pub fn flush_handle(&self) -> MappedFlush
Returns a checked flush barrier that follows this owner’s remaps.
Retain this before adopting the mapping into a generic doublets store,
then attach it with DoubletsStorage::with_mapped_flush.
Rejected growth of values without drop glue retains the existing view
and barrier. Failed shrink or destructor growth can leave unsafe upstream
allocator state and invalidate the barrier. Reopening alone cannot establish
safe cleanup. Dropping a valid owner closes every retained handle.
Source§impl<T: FileMappedValue> PersistentFileMapped<T>
impl<T: FileMappedValue> PersistentFileMapped<T>
Sourcepub fn open_existing(file: File) -> Result<Self>
pub fn open_existing(file: File) -> Result<Self>
Maps file and adopts the capacity represented by its existing bytes.
Unlike Self::new, which starts with a logical capacity of zero, this
constructor makes every complete T already present in the file
immediately visible through RawMem::allocated. Any trailing bytes
that do not form a complete T are left untouched and ignored.
#![deny(unsafe_code)]
use std::fs::File;
use link_cli::doublets::unit::LinkPart;
use link_cli::PersistentFileMapped;
let file = File::options().read(true).write(true).open("links.data")?;
let mapped = PersistentFileMapped::<LinkPart<usize>>::open_existing(file)?;Trait Implementations§
Source§impl<T: Debug> Debug for PersistentFileMapped<T>
impl<T: Debug> Debug for PersistentFileMapped<T>
Source§impl<T> Drop for PersistentFileMapped<T>
impl<T> Drop for PersistentFileMapped<T>
Source§impl<T> RawMem for PersistentFileMapped<T>
impl<T> RawMem for PersistentFileMapped<T>
Source§fn grow_filled(
&mut self,
cap: usize,
value: Self::Item,
) -> MemResult<&mut [Self::Item]>
fn grow_filled( &mut self, cap: usize, value: Self::Item, ) -> MemResult<&mut [Self::Item]>
Fills only the genuinely uninitialised tail of the grown region, keeping the bytes that were already persisted in the file.
Source§fn allocated(&self) -> &[Self::Item]
fn allocated(&self) -> &[Self::Item]
Source§fn allocated_mut(&mut self) -> &mut [Self::Item]
fn allocated_mut(&mut self) -> &mut [Self::Item]
Source§unsafe fn grow(
&mut self,
addition: usize,
fill: impl FnOnce(usize, (&mut [Self::Item], &mut [MaybeUninit<Self::Item>])),
) -> MemResult<&mut [Self::Item]>
unsafe fn grow( &mut self, addition: usize, fill: impl FnOnce(usize, (&mut [Self::Item], &mut [MaybeUninit<Self::Item>])), ) -> MemResult<&mut [Self::Item]>
cap elements. Read moreSource§fn shrink(&mut self, cap: usize) -> MemResult<()>
fn shrink(&mut self, cap: usize) -> MemResult<()>
cap elements, dropping them.Source§fn size_hint(&self) -> Option<usize>
fn size_hint(&self) -> Option<usize>
Source§unsafe fn grow_zeroed(&mut self, cap: usize) -> Result<&mut [Self::Item], Error>
unsafe fn grow_zeroed(&mut self, cap: usize) -> Result<&mut [Self::Item], Error>
cap elements, zeroing only the uninitialized tail.
Elements already initialized by the backend are preserved. Read moreSource§unsafe fn grow_zeroed_exact(
&mut self,
cap: usize,
) -> Result<&mut [Self::Item], Error>
unsafe fn grow_zeroed_exact( &mut self, cap: usize, ) -> Result<&mut [Self::Item], Error>
grow_zeroed, preserving initialized elements. Read moreSource§fn grow_with(
&mut self,
addition: usize,
f: impl FnMut() -> Self::Item,
) -> Result<&mut [Self::Item], Error>
fn grow_with( &mut self, addition: usize, f: impl FnMut() -> Self::Item, ) -> Result<&mut [Self::Item], Error>
addition elements, calling f only for uninitialized elements.
Elements already initialized by the backend are preserved.Source§unsafe fn grow_with_exact(
&mut self,
addition: usize,
f: impl FnMut() -> Self::Item,
) -> Result<&mut [Self::Item], Error>
unsafe fn grow_with_exact( &mut self, addition: usize, f: impl FnMut() -> Self::Item, ) -> Result<&mut [Self::Item], Error>
Source§unsafe fn grow_filled_exact(
&mut self,
cap: usize,
value: Self::Item,
) -> Result<&mut [Self::Item], Error>
unsafe fn grow_filled_exact( &mut self, cap: usize, value: Self::Item, ) -> Result<&mut [Self::Item], Error>
Auto Trait Implementations§
impl<T> Forget for PersistentFileMapped<T>
impl<T> Freeze for PersistentFileMapped<T>where
FileMapped<T>: Freeze,
impl<T> RefUnwindSafe for PersistentFileMapped<T>where
FileMapped<T>: RefUnwindSafe,
impl<T> Send for PersistentFileMapped<T>where
FileMapped<T>: Send,
impl<T> Sync for PersistentFileMapped<T>where
FileMapped<T>: Sync,
impl<T> Unpin for PersistentFileMapped<T>where
FileMapped<T>: Unpin,
impl<T> UnsafeUnpin for PersistentFileMapped<T>where
FileMapped<T>: UnsafeUnpin,
impl<T> UnwindSafe for PersistentFileMapped<T>where
FileMapped<T>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<All> ErasedMem for All
impl<All> ErasedMem for All
Source§fn erased_allocated(&self) -> &[<All as ErasedMem>::Item]
fn erased_allocated(&self) -> &[<All as ErasedMem>::Item]
Source§fn erased_allocated_mut(&mut self) -> &mut [<All as ErasedMem>::Item]
fn erased_allocated_mut(&mut self) -> &mut [<All as ErasedMem>::Item]
Source§unsafe fn erased_grow(
&mut self,
cap: usize,
fill: &mut dyn FillFn<<All as ErasedMem>::Item>,
) -> Result<&mut [<All as ErasedMem>::Item], Error>
unsafe fn erased_grow( &mut self, cap: usize, fill: &mut dyn FillFn<<All as ErasedMem>::Item>, ) -> Result<&mut [<All as ErasedMem>::Item], Error>
Source§fn erased_shrink(&mut self, cap: usize) -> Result<(), Error>
fn erased_shrink(&mut self, cap: usize) -> Result<(), Error>
cap elements (type-erased).