pub trait Filesystem: MaybeSendSync + Debug {
// Required methods
fn read<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn write_atomic<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
path: &'life1 str,
bytes: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn metadata<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Metadata>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn read_dir<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<DirEntry>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn walk<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
max_depth: Option<usize>,
) -> Pin<Box<dyn Future<Output = Result<Vec<WalkEntry>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided method
fn rename<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
from: &'life1 str,
to: &'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 { ... }
}Expand description
The operations the built-in fs tools need from a filesystem.
Implementations are responsible for normalising errors into
crate::error::Error with a useful message.
The Debug supertrait lets GeminiBackendConfig (which now stores
an optional Filesystem) derive Debug; impl authors typically
satisfy it with #[derive(Debug)] on a marker struct.
Required Methods§
Sourcefn read<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn read<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Read the full contents of a file as bytes.
Errors if path does not exist, is a directory, or is otherwise
unreadable.
Sourcefn write_atomic<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
path: &'life1 str,
bytes: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn write_atomic<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
path: &'life1 str,
bytes: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Atomically write bytes to path, creating any missing parent
directories. Replaces any existing file at the destination.
Atomicity contract: a concurrent reader observes either the
full pre-write contents or the full post-write contents — never
a partial / torn write. A crash mid-write must not leave a
partially-written file at path. The native impl satisfies this
via tempfile + rename in the destination directory; an OPFS impl
would use the OPFS sync access handle’s truncate + write + flush sequence.
Sourcefn metadata<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Metadata>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn metadata<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Metadata>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Return metadata for path, or None if the path does not exist.
Other I/O errors (e.g. permission denied) propagate as Err.
Sourcefn read_dir<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<DirEntry>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn read_dir<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<DirEntry>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
List the immediate children of path, sorted by name.
Errors if path does not exist or is not a directory.
Sourcefn walk<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
max_depth: Option<usize>,
) -> Pin<Box<dyn Future<Output = Result<Vec<WalkEntry>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn walk<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
max_depth: Option<usize>,
) -> Pin<Box<dyn Future<Output = Result<Vec<WalkEntry>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Recursively walk path, returning every entry under it (files
and directories). Symlinks are not followed. If max_depth is
Some(d), recursion is limited to depth d (the root itself is
depth 0). Implementations may return entries in any order.
Sourcefn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Delete path. If path names a directory, the directory and
all its contents are removed (recursive). If path does not
exist, returns Err. Symlinks are removed, not followed.
Provided Methods§
Sourcefn rename<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
from: &'life1 str,
to: &'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,
fn rename<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
from: &'life1 str,
to: &'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,
Rename / move from to to. Both arguments are relative paths
in the backend’s address space. If to already exists, the
behaviour is backend-defined (native uses platform default;
OPFS errors out).
Default impl is read + write_atomic + delete — works for any backend but doesn’t preserve metadata. Backends with a native rename should override (NativeFilesystem does).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".