Skip to main content

PersistentFileMapped

Struct PersistentFileMapped 

Source
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>

Source

pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self>

Opens (creating it if needed) the file at path and maps it.

Source

pub fn new(file: File) -> Result<Self>

Maps an already-opened file.

Source

pub fn inner(&self) -> &FileMapped<T>

Borrows the wrapped [FileMapped].

Source

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>

Source

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>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Drop for PersistentFileMapped<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

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,

Fills only the genuinely uninitialised tail of the grown region, keeping the bytes that were already persisted in the file.

Source§

type Item = T

The element type stored in this memory.
Source§

fn allocated(&self) -> &[Self::Item]

Returns a shared slice of all currently initialized elements.
Source§

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]>

Low-level growth: extends the memory by cap elements. Read more
Source§

fn shrink(&mut self, cap: usize) -> MemResult<()>

Removes the last cap elements, dropping them.
§

fn size_hint(&self) -> Option<usize>

Returns an optional hint about the total capacity, if known.
§

unsafe fn grow_assumed( &mut self, cap: usize, ) -> Result<&mut [Self::Item], Error>

grow which assumes that the memory is already initialized Read more
§

unsafe fn grow_zeroed(&mut self, cap: usize) -> Result<&mut [Self::Item], Error>

Grows by 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>

Equivalent to grow_zeroed, preserving initialized elements. Read more
§

fn grow_with( &mut self, addition: usize, f: impl FnMut() -> Self::Item, ) -> Result<&mut [Self::Item], Error>

Grows by 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>

Safety Read more
§

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>
where R: RangeBounds<usize>, Self::Item: Clone,

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,

Grows by cloning all elements from src.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<All> ErasedMem for All
where All: RawMem + ?Sized,

§

type Item = <All as RawMem>::Item

The element type.
§

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]

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>

Safety Read more
§

fn erased_shrink(&mut self, cap: usize) -> Result<(), Error>

Removes the last cap elements (type-erased).
§

fn erased_size_hint(&self) -> Option<usize>

Returns an optional capacity hint (type-erased).
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.