pub struct InMemoryStorage { /* private fields */ }vfs only.Expand description
In-memory VFS storage implementation.
Stores files and directories in memory using HashMap and HashSet.
Thread-safe via a single RwLock over the combined state.
Total file content is capped at DEFAULT_MAX_BYTES unless changed with
InMemoryStorage::with_max_bytes; operations that would exceed the cap
fail with VfsError::QuotaExceeded, which guests see as ENOSPC.
Implementations§
Source§impl InMemoryStorage
impl InMemoryStorage
Sourcepub fn new() -> InMemoryStorage
pub fn new() -> InMemoryStorage
Create a new empty in-memory storage with root directory.
Total file content is capped at DEFAULT_MAX_BYTES.
Sourcepub fn with_max_bytes(max_bytes: u64) -> InMemoryStorage
pub fn with_max_bytes(max_bytes: u64) -> InMemoryStorage
Create a new empty in-memory storage with an explicit size cap.
max_bytes bounds the total content of all files combined. Because the
contents live in host memory and a sandboxed guest picks its own write
offsets, this is a limit on how much memory the guest can make the host
allocate - keep it well below what the host can afford to lose.
Sourcepub async fn snapshot(&self) -> InMemorySnapshot
pub async fn snapshot(&self) -> InMemorySnapshot
Capture the entire contents (files and directories) as a snapshot.
The snapshot is an independent copy; later mutations to this storage do not affect it.
Sourcepub async fn restore(&self, snapshot: &InMemorySnapshot)
pub async fn restore(&self, snapshot: &InMemorySnapshot)
Replace this storage’s entire contents with a snapshot, in place.
The storage’s identity is preserved, so any Arc<dyn VfsStorage> handles
(e.g. those wired into a running sandbox) continue to refer to it and see
the restored contents.
Sourcepub fn from_snapshot(snapshot: &InMemorySnapshot) -> InMemoryStorage
pub fn from_snapshot(snapshot: &InMemorySnapshot) -> InMemoryStorage
Create a new, independent storage initialized from a snapshot.
Useful for forking a session: the returned storage shares no state with the original, so the two can diverge freely.
Trait Implementations§
Source§impl Debug for InMemoryStorage
impl Debug for InMemoryStorage
Source§impl Default for InMemoryStorage
impl Default for InMemoryStorage
Source§fn default() -> InMemoryStorage
fn default() -> InMemoryStorage
Source§impl VfsStorage for InMemoryStorage
impl VfsStorage for InMemoryStorage
Source§fn as_any(&self) -> Option<&(dyn Any + 'static)>
fn as_any(&self) -> Option<&(dyn Any + 'static)>
Source§fn read<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, VfsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryStorage: 'async_trait,
fn read<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, VfsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryStorage: 'async_trait,
Source§fn read_at<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
offset: u64,
len: u64,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, VfsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryStorage: 'async_trait,
fn read_at<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
offset: u64,
len: u64,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, VfsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryStorage: 'async_trait,
Source§fn write<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
path: &'life1 str,
data: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<(), VfsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
InMemoryStorage: 'async_trait,
fn write<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
path: &'life1 str,
data: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<(), VfsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
InMemoryStorage: 'async_trait,
Source§fn write_at<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
path: &'life1 str,
offset: u64,
data: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<(), VfsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
InMemoryStorage: 'async_trait,
fn write_at<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
path: &'life1 str,
offset: u64,
data: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<(), VfsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
InMemoryStorage: 'async_trait,
Source§fn set_size<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
size: u64,
) -> Pin<Box<dyn Future<Output = Result<(), VfsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryStorage: 'async_trait,
fn set_size<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
size: u64,
) -> Pin<Box<dyn Future<Output = Result<(), VfsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryStorage: 'async_trait,
Source§fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), VfsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryStorage: 'async_trait,
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), VfsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryStorage: 'async_trait,
Source§fn exists<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, VfsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryStorage: 'async_trait,
fn exists<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, VfsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryStorage: 'async_trait,
Source§fn list<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<DirEntry>, VfsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryStorage: 'async_trait,
fn list<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<DirEntry>, VfsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryStorage: 'async_trait,
Source§fn stat<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Metadata, VfsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryStorage: 'async_trait,
fn stat<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Metadata, VfsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryStorage: 'async_trait,
Source§fn mkdir<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), VfsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryStorage: 'async_trait,
fn mkdir<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), VfsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryStorage: 'async_trait,
Source§fn rmdir<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), VfsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryStorage: 'async_trait,
fn rmdir<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), VfsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryStorage: 'async_trait,
Source§fn rename<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
from: &'life1 str,
to: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<(), VfsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
InMemoryStorage: 'async_trait,
fn rename<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
from: &'life1 str,
to: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<(), VfsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
InMemoryStorage: 'async_trait,
Auto Trait Implementations§
impl !Freeze for InMemoryStorage
impl !RefUnwindSafe for InMemoryStorage
impl !UnwindSafe for InMemoryStorage
impl Send for InMemoryStorage
impl Sync for InMemoryStorage
impl Unpin for InMemoryStorage
impl UnsafeUnpin for InMemoryStorage
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
Source§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
Source§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
self file descriptor.Source§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
Source§fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: Sized + AsFilelike,
fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: Sized + AsFilelike,
self file descriptor. Read moreSource§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 more