Skip to main content

MemoryStrategy

Enum MemoryStrategy 

Source
#[non_exhaustive]
pub enum MemoryStrategy { Bounded, Auto, Mirrored, }
Expand description

How much memory a read-write open may use to hold the file being edited.

The two read-write backends differ in memory, not in what they can express: a bounded session reads through a handle and holds only what a commit is building, while a mirrored session materializes the whole file in memory. Bounded is the better default when it applies, but it cannot yet edit every file — a pre-v2 (non-latest-format) superblock or a userblock still needs the mirror.

This is what a caller says about that trade-off, on FileAccessProperties::with_memory_strategy. Leaving it unset lets the entry point decide: File::open_rw prefers the bounded engine and falls back to the mirror (Auto). Stating Bounded refuses instead of falling back.

This is a request, so it is deliberately not the type a file answers with: File::edit_backing returns an EditBacking, which cannot express Auto.

Sealed: unlike FileLocking or FileSpaceStrategy, whose variant sets mirror a closed C-library enum, this is a policy this crate invented, so a fourth strategy must not be a breaking change.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Bounded

Never build a whole-file mirror. A file the bounded engine cannot edit is refused at open with Error::EditUnsupported, before anything is staged.

§

Auto

Prefer the bounded engine, but fall back to the whole-file mirror for a file it cannot edit, rather than refusing. Memory then scales with the file, which is the cost of the file opening at all. What File::open_rw uses when nothing is asked for.

Two files reach that fallback, and no others: one with a pre-v2 (non-latest-format) superblock, and one with a userblock (a non-zero base address). Every other file a read-write open accepts is edited bounded, whatever its FileSpaceStrategy, whether or not it persists its free space, and however large it is. A paged file with no persisted free space is refused by both backings rather than mirrored, so it is not a third case. The list being exhaustive is what makes “prefer bounded” a guarantee to budget against: wherever Bounded opens a file, Auto gives the same backing.

§

Mirrored

Always build the whole-file mirror, whatever the file looks like. What File::open_rw did before it learned to dispatch.

Trait Implementations§

Source§

impl Clone for MemoryStrategy

Source§

fn clone(&self) -> MemoryStrategy

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 Copy for MemoryStrategy

Source§

impl Debug for MemoryStrategy

Source§

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

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

impl Eq for MemoryStrategy

Source§

impl From<EditBacking> for MemoryStrategy

Source§

fn from(backing: EditBacking) -> Self

Turns an outcome back into the request that pins it, so a caller can reopen a file onto the backing it got the first time: with_memory_strategy(file.edit_backing().unwrap().into()).

Source§

impl PartialEq for MemoryStrategy

Source§

fn eq(&self, other: &MemoryStrategy) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for MemoryStrategy

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> Same for T

Source§

type Output = T

Should always be Self
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.