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>
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> 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]
Returns a shared slice of all currently initialized elements.
Source§fn allocated_mut(&mut self) -> &mut [Self::Item]
fn allocated_mut(&mut self) -> &mut [Self::Item]
Returns a mutable slice of all currently initialized elements.
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]>
Low-level growth: extends the memory by
cap elements. Read moreSource§fn shrink(&mut self, cap: usize) -> MemResult<()>
fn shrink(&mut self, cap: usize) -> MemResult<()>
Removes the last
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>
Safety 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>
Safety 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>
Grows by
addition elements, initializing each with the closure f.§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>
Safety Read more
§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,
Safety Read more
§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>
Grows by cloning a sub-range of the currently allocated data.
§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,
Grows by cloning all elements from
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
Mutably borrows from an owned value. Read more
§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]
Returns a shared slice of initialized elements (type-erased).
§fn erased_allocated_mut(&mut self) -> &mut [<All as ErasedMem>::Item]
fn erased_allocated_mut(&mut self) -> &mut [<All as ErasedMem>::Item]
Returns a mutable slice of initialized elements (type-erased).
§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>
Safety Read more
§fn erased_shrink(&mut self, cap: usize) -> Result<(), Error>
fn erased_shrink(&mut self, cap: usize) -> Result<(), Error>
Removes the last
cap elements (type-erased).§fn erased_size_hint(&self) -> Option<usize>
fn erased_size_hint(&self) -> Option<usize>
Returns an optional capacity hint (type-erased).