#[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
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
impl Clone for MemoryStrategy
Source§fn clone(&self) -> MemoryStrategy
fn clone(&self) -> MemoryStrategy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for MemoryStrategy
Source§impl Debug for MemoryStrategy
impl Debug for MemoryStrategy
impl Eq for MemoryStrategy
Source§impl From<EditBacking> for MemoryStrategy
impl From<EditBacking> for MemoryStrategy
Source§fn from(backing: EditBacking) -> Self
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()).