Skip to main content

MemoryFilesystem

Struct MemoryFilesystem 

Source
pub struct MemoryFilesystem { /* private fields */ }
Expand description

Files held in memory.

What a test wants: no directory to create, no cleanup to forget, and the same Filesystem the application uses in production. It also enforces the same path rules, so a test cannot pass with a path the local or S3 driver would refuse.

Implementations§

Source§

impl MemoryFilesystem

Source

pub fn new() -> Self

An empty filesystem.

Source

pub fn len(&self) -> usize

How many files are held.

Source

pub fn is_empty(&self) -> bool

Whether nothing is held.

Source

pub fn paths(&self) -> Vec<String>

Every path, sorted. For asserting on what a test wrote.

Trait Implementations§

Source§

impl Debug for MemoryFilesystem

Source§

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

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

impl Default for MemoryFilesystem

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Filesystem for MemoryFilesystem

Source§

fn name(&self) -> &str

A label for diagnostics — "local", "s3", "memory".
Source§

fn get<'a>(&'a self, path: &'a str) -> BoxFuture<'a, Result<Option<Bytes>>>

Read a file. None if it is not there. Read more
Source§

fn put<'a>( &'a self, path: &'a str, contents: Bytes, ) -> BoxFuture<'a, Result<()>>

Write a file, creating any directories it needs and replacing what was there.
Source§

fn delete<'a>(&'a self, path: &'a str) -> BoxFuture<'a, Result<bool>>

Delete a file. true if it was there.
Source§

fn exists<'a>(&'a self, path: &'a str) -> BoxFuture<'a, Result<bool>>

Whether a file exists.
Source§

fn metadata<'a>( &'a self, path: &'a str, ) -> BoxFuture<'a, Result<Option<Metadata>>>

A file’s metadata, or None.
Source§

fn list<'a>(&'a self, prefix: &'a str) -> BoxFuture<'a, Result<Vec<Metadata>>>

Every file directly under prefix, not recursing. Read more
Source§

fn copy<'a>(&'a self, from: &'a str, to: &'a str) -> BoxFuture<'a, Result<()>>

Copy a file. Read more
Source§

fn rename<'a>(&'a self, from: &'a str, to: &'a str) -> BoxFuture<'a, Result<()>>

Move a file.
Source§

fn url(&self, path: &str) -> Option<String>

A URL a browser can fetch, if this driver has one. 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<F> FilesystemExt for F
where F: Filesystem + ?Sized,

Source§

fn get_string<'life0, 'life1, 'async_trait>( &'life0 self, path: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Read a file as a string.
Source§

fn put_string<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, path: &'life1 str, contents: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Write a string.
Source§

fn get_or_fail<'life0, 'life1, 'async_trait>( &'life0 self, path: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Bytes>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Read a file, failing with a 404 if it is absent. Read more
Source§

fn size<'life0, 'life1, 'async_trait>( &'life0 self, path: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<u64>>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

A file’s size.
Source§

fn last_modified<'life0, 'life1, 'async_trait>( &'life0 self, path: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<DateTime<Utc>>>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

When a file was last written.
Source§

fn append<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, path: &'life1 str, contents: &'life2 [u8], ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Append to a file, creating it if absent. 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, 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.