Skip to main content

MemMapCfg

Struct MemMapCfg 

Source
pub struct MemMapCfg {
    pub module_id: u8,
    pub path: PathBuf,
    pub version: u32,
    pub initial_t: usize,
    pub sync_interval: Option<Duration>,
    pub page_size: Option<PageSize>,
}
Expand description

Configurations for MemMap

§Example

use frozen_core::memmap::MemMapCfg;
use std::time::Duration;

let cfg = MemMapCfg {
    module_id: 1,
    path: std::path::PathBuf::from("test.db"),
    version: 1,
    initial_t: 512,
    sync_interval: Some(Duration::from_millis(0x64)),
    page_size: None,
};

assert_eq!(cfg.version, 1);
assert_eq!(cfg.initial_t, 512);
assert_eq!(cfg.sync_interval, Some(Duration::from_millis(0x64)));
assert_eq!(cfg.page_size, None);

Fields§

§module_id: u8

Identifier used while error propagation

§path: PathBuf

Base path for/of the file

§Notes

  • The caller must make sure that the path represents a file and all the parent directories included in the path do exist
  • The actual file created on disk is derived by appending the version to the base file name (e.g. data.bin with version 1 becomes data_1.bin)
§version: u32

Schema or layout version of the underlying memory-mapped file

Because the binary layout on disk is constructed according to the initial type T and structural parameters, MemMap strictly requires type invariants across a file’s lifetime

When an application evolves its data structures or migrates T, incrementing version ensures a new versioned backing file (<name>_<ver>) is created on disk without corrupting or clashing with previously persisted data

§initial_t: usize

Number of T elements to pre-allocate on fs when MemMap is initialized

Initial file length will be core::mem::size_of::<T>() * initial_t (bytes)

§sync_interval: Option<Duration>

Optional interval for the background sync thread

If Some(duration), a background worker thread is spawned which flushes dirty mapped pages at this interval; and if None, background sync is disabled and durability advances via manual sync or forced tickets

§page_size: Option<PageSize>

Configured page size unit for file allocation and growth

Must be a power of 2 and at least 4096 bytes (PageSize::K4). If None, defaults to the platform/host page size ([PlatformMemMap::page_size()]).

Trait Implementations§

Source§

impl Clone for MemMapCfg

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MemMapCfg

Source§

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

Formats the value using the given formatter. Read more

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

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.