pub struct MemVault { /* private fields */ }Expand description
An in-memory vault. Interior mutability, so it can be shared as
Arc<dyn Vault> and still written to.
Implementations§
Source§impl MemVault
impl MemVault
Sourcepub const DEFAULT_ROOT: &'static str = "/mbr-mem-vault"
pub const DEFAULT_ROOT: &'static str = "/mbr-mem-vault"
The default namespace root. Deliberately a path no real repository would sit at, so a key that is accidentally opened as a file fails loudly instead of reading something.
Sourcepub fn with_root(root: impl Into<PathBuf>) -> Self
pub fn with_root(root: impl Into<PathBuf>) -> Self
An empty vault whose Vault::root is root.
Sourcepub fn with_file(self, path: &str, contents: impl AsRef<[u8]>) -> Self
pub fn with_file(self, path: &str, contents: impl AsRef<[u8]>) -> Self
Builder form of Self::insert_file.
Sourcepub fn with_dir(self, path: &str) -> Self
pub fn with_dir(self, path: &str) -> Self
Builder form of Self::insert_dir.
Sourcepub fn insert_file(&self, path: &str, contents: impl AsRef<[u8]>)
pub fn insert_file(&self, path: &str, contents: impl AsRef<[u8]>)
Sourcepub fn insert_dir(&self, path: &str)
pub fn insert_dir(&self, path: &str)
Sourcepub fn set_availability(&self, path: &str, availability: Availability)
pub fn set_availability(&self, path: &str, availability: Availability)
Sourcepub fn set_dir_availability(&self, path: &str, availability: Availability)
pub fn set_dir_availability(&self, path: &str, availability: Availability)
Marks a directory as one whose listing is not downloaded (or back):
its parent lists it, stat finds it, but Vault::list_dir fails
VaultError::NotDownloaded — an iCloud Drive folder on iOS that
nothing has listed yet. Unlike a file’s, a directory’s listing does not
arrive on Vault::request_download: the request is recorded and the
test makes it arrive, as the provider would, some time later.
§Panics
When there is no such directory.
Sourcepub fn set_modified(&self, path: &str, modified: SystemTime)
pub fn set_modified(&self, path: &str, modified: SystemTime)
Sourcepub fn hold_downloads(&self, held: bool)
pub fn hold_downloads(&self, held: bool)
Whether a requested download stays pending (true) or completes at
once (false, the default). Models a provider that is offline or slow.
Sourcepub fn download_requests(&self) -> Vec<VaultPath>
pub fn download_requests(&self) -> Vec<VaultPath>
Every path passed to Vault::request_download so far, in order.
Trait Implementations§
Source§impl Vault for MemVault
impl Vault for MemVault
Source§fn root(&self) -> &Path
fn root(&self) -> &Path
Vault::keys live under. For LocalVault, the
canonical repository root; for any other vault, an identifier that is
never opened.Source§fn stat(&self, path: &VaultPath) -> Result<Option<Entry>, VaultError>
fn stat(&self, path: &VaultPath) -> Result<Option<Entry>, VaultError>
path (following symlinks), or None when nothing is
there.Source§fn list_dir(&self, dir: &VaultPath) -> Result<Vec<Entry>, VaultError>
fn list_dir(&self, dir: &VaultPath) -> Result<Vec<Entry>, VaultError>
dir, in no particular order. Read moreSource§fn canonicalize(&self, path: &VaultPath) -> Result<VaultPath, VaultError>
fn canonicalize(&self, path: &VaultPath) -> Result<VaultPath, VaultError>
path and returns where it really is inside the
vault. Read moreSource§fn read_prefix(
&self,
path: &VaultPath,
max_len: usize,
) -> Result<Vec<u8>, VaultError>
fn read_prefix( &self, path: &VaultPath, max_len: usize, ) -> Result<Vec<u8>, VaultError>
max_len bytes (frontmatter extraction reads 8 KB).Source§fn availability(&self, path: &VaultPath) -> Availability
fn availability(&self, path: &VaultPath) -> Availability
path is on this device, decided without reading
it — the check a server makes before handing a file to a reader that
would block on (or fail half-way through) a not-downloaded one. Read moreSource§fn write_atomic(&self, path: &VaultPath, bytes: &[u8]) -> Result<(), VaultError>
fn write_atomic(&self, path: &VaultPath, bytes: &[u8]) -> Result<(), VaultError>
path with bytes atomically: readers see the
old content or the new, never a mix, and a failure leaves the old file.
The parent directory must exist. An existing file’s permissions are
kept. Read moreSource§fn create_dir_all(&self, path: &VaultPath) -> Result<(), VaultError>
fn create_dir_all(&self, path: &VaultPath) -> Result<(), VaultError>
path and any missing ancestors as directories.Source§fn remove_file(&self, path: &VaultPath) -> Result<(), VaultError>
fn remove_file(&self, path: &VaultPath) -> Result<(), VaultError>
path.Source§fn rename(&self, from: &VaultPath, to: &VaultPath) -> Result<(), VaultError>
fn rename(&self, from: &VaultPath, to: &VaultPath) -> Result<(), VaultError>
from to to, replacing a file at to.Source§fn request_download(&self, paths: &[VaultPath])
fn request_download(&self, paths: &[VaultPath])
Source§fn read_range(
&self,
path: &VaultPath,
offset: u64,
len: usize,
) -> Result<Vec<u8>, VaultError>
fn read_range( &self, path: &VaultPath, offset: u64, len: usize, ) -> Result<Vec<u8>, VaultError>
len bytes starting at byte offset: fewer at the end of the
file, none past it. The streaming and Range path for files a vault
has no Vault::local_path for (mbr_server serves those in chunks). Read moreSource§fn local_path(&self, _path: &VaultPath) -> Option<PathBuf>
fn local_path(&self, _path: &VaultPath) -> Option<PathBuf>
path, when one exists — the fast path for
consumers that need one (ServeFile, grep’s search_path, ffmpeg,
pdfium, mmap). None means “read it through the vault”.Source§fn read_to_string(&self, path: &VaultPath) -> Result<String, VaultError>
fn read_to_string(&self, path: &VaultPath) -> Result<String, VaultError>
VaultError::Io with
ErrorKind::InvalidData, as std::fs::read_to_string reports it.Source§fn vault_path(&self, key: &Path) -> Result<VaultPath, VaultError>
fn vault_path(&self, key: &Path) -> Result<VaultPath, VaultError>
Vault::key.
Lexical: it does not resolve symlinks.Source§fn is_file(&self, path: &VaultPath) -> bool
fn is_file(&self, path: &VaultPath) -> bool
path is an existing file. Errors read as false, as
Path::is_file does.Source§fn is_dir(&self, path: &VaultPath) -> bool
fn is_dir(&self, path: &VaultPath) -> bool
path is an existing directory. Errors read as false.Source§fn is_read_only(&self, _path: &VaultPath) -> bool
fn is_read_only(&self, _path: &VaultPath) -> bool
path lies in a read-only part of the vault — a symlink
mount’s location or anything under it. Lexical: callers pass resolved
(canonical) paths, and the vault’s own write methods re-check the
canonical form. false for vaults without mounts.Auto Trait Implementations§
impl !Freeze for MemVault
impl !RefUnwindSafe for MemVault
impl Send for MemVault
impl Sync for MemVault
impl Unpin for MemVault
impl UnsafeUnpin for MemVault
impl UnwindSafe for MemVault
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);