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 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]>where
Self::Item: Clone,
fn grow_filled(
&mut self,
cap: usize,
value: Self::Item,
) -> MemResult<&mut [Self::Item]>where
Self::Item: Clone,
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.§unsafe fn grow_assumed(
&mut self,
cap: usize,
) -> Result<&mut [Self::Item], Error>
unsafe fn grow_assumed( &mut self, cap: usize, ) -> Result<&mut [Self::Item], Error>
§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 more§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 more§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.§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>
§unsafe fn grow_filled_exact(
&mut self,
cap: usize,
value: Self::Item,
) -> Result<&mut [Self::Item], Error>where
Self::Item: Clone,
unsafe fn grow_filled_exact(
&mut self,
cap: usize,
value: Self::Item,
) -> Result<&mut [Self::Item], Error>where
Self::Item: Clone,
§fn grow_within<R>(&mut self, range: R) -> Result<&mut [Self::Item], Error>
fn grow_within<R>(&mut self, range: R) -> Result<&mut [Self::Item], Error>
§fn grow_from_slice(
&mut self,
src: &[Self::Item],
) -> Result<&mut [Self::Item], Error>where
Self::Item: Clone,
fn grow_from_slice(
&mut self,
src: &[Self::Item],
) -> Result<&mut [Self::Item], Error>where
Self::Item: Clone,
src.Auto Trait Implementations§
impl<T> Freeze for PersistentFileMapped<T>
impl<T> RefUnwindSafe for PersistentFileMapped<T>where
T: RefUnwindSafe,
impl<T> Send for PersistentFileMapped<T>where
T: Send,
impl<T> Sync for PersistentFileMapped<T>where
T: Sync,
impl<T> Unpin for PersistentFileMapped<T>where
T: Unpin,
impl<T> UnsafeUnpin for PersistentFileMapped<T>
impl<T> UnwindSafe for PersistentFileMapped<T>where
T: RefUnwindSafe + 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
§impl<All> ErasedMem for Allwhere
All: RawMem + ?Sized,
impl<All> ErasedMem for Allwhere
All: RawMem + ?Sized,
§fn erased_allocated(&self) -> &[<All as ErasedMem>::Item]
fn erased_allocated(&self) -> &[<All as ErasedMem>::Item]
§fn erased_allocated_mut(&mut self) -> &mut [<All as ErasedMem>::Item]
fn erased_allocated_mut(&mut self) -> &mut [<All as ErasedMem>::Item]
§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>
§fn erased_shrink(&mut self, cap: usize) -> Result<(), Error>
fn erased_shrink(&mut self, cap: usize) -> Result<(), Error>
cap elements (type-erased).