pub struct Client { /* private fields */ }Expand description
One concurrent ZeroFS session and identity. Calls wait during reconnect. Cancelling an unsettled fid-state request retires the connection that carried it; the session reconnects and replays if that connection is still current. Cancelling a dispatched mutation leaves its outcome ambiguous.
Paths are bytes, as on POSIX and the 9P wire: every path parameter is
impl AsRef<Path>, so &str, PathBuf, and OsStr::from_bytes(..) for
non-UTF-8 names all work.
Implementations§
Source§impl Client
impl Client
Sourcepub async fn connect(target: &str) -> Result<Arc<Client>, ZeroFsError>
pub async fn connect(target: &str) -> Result<Arc<Client>, ZeroFsError>
Connect with defaults. Native targets: "unix:/sock",
"tcp://host:port", "host:port", "host" (port 5564), or a bare
filesystem path (unix socket). A comma-separated string forms an HA
target set. Browser WASM targets are "ws://..." and "wss://...".
Sourcepub async fn connect_with(
target: &str,
opts: ConnectOptions,
) -> Result<Arc<Client>, ZeroFsError>
pub async fn connect_with( target: &str, opts: ConnectOptions, ) -> Result<Arc<Client>, ZeroFsError>
Connect with explicit identity, timeout, and tuning.
Sourcepub async fn connect_multi(
targets: &[String],
) -> Result<Arc<Client>, ZeroFsError>
pub async fn connect_multi( targets: &[String], ) -> Result<Arc<Client>, ZeroFsError>
Connect across a target set, probing for the serving leader on reconnect.
Sourcepub fn capabilities(&self) -> Capabilities
pub fn capabilities(&self) -> Capabilities
Negotiated properties, fixed for the lifetime of this logical session.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Whether the underlying session is currently live. During transparent reconnect this is false while operations wait for replay to finish.
Sourcepub fn traffic_stats(&self) -> TrafficStats
pub fn traffic_stats(&self) -> TrafficStats
Cumulative 9P wire traffic for this client, including reconnects.
Sourcepub async fn close(&self)
pub async fn close(&self)
Marks the client closed and schedules the root fid for release. This call
is idempotent and non-blocking. Existing File and Dir handles remain open.
Sourcepub async fn read(&self, path: impl AsRef<Path>) -> Result<Bytes, ZeroFsError>
pub async fn read(&self, path: impl AsRef<Path>) -> Result<Bytes, ZeroFsError>
Read the entire file into memory. Returns Bytes: a whole file that
fits in one round trip comes back with no copy.
Sourcepub async fn read_range(
&self,
path: impl AsRef<Path>,
offset: u64,
len: u32,
) -> Result<Bytes, ZeroFsError>
pub async fn read_range( &self, path: impl AsRef<Path>, offset: u64, len: u32, ) -> Result<Bytes, ZeroFsError>
Read up to len bytes at offset; a shorter result means EOF.
Sourcepub async fn write(
&self,
path: impl AsRef<Path>,
data: &[u8],
) -> Result<(), ZeroFsError>
pub async fn write( &self, path: impl AsRef<Path>, data: &[u8], ) -> Result<(), ZeroFsError>
Create-or-truncate path (mode 0o644) and write all of data
(composed client-side: open/create + truncate + write).
Sourcepub async fn append(
&self,
path: impl AsRef<Path>,
data: &[u8],
) -> Result<u64, ZeroFsError>
pub async fn append( &self, path: impl AsRef<Path>, data: &[u8], ) -> Result<u64, ZeroFsError>
Append data at end-of-file (open-or-create + fstat + positioned
write, composed client-side); returns the offset where the data landed.
Last-writer-wins under concurrent appenders.
Sourcepub async fn stat(
&self,
path: impl AsRef<Path>,
) -> Result<Metadata, ZeroFsError>
pub async fn stat( &self, path: impl AsRef<Path>, ) -> Result<Metadata, ZeroFsError>
Report the entry at path without following symlinks; anywhere: a
path THROUGH a symlinked directory fails NotADirectory (9P walks are
literal; this applies to every path-taking method). Self::metadata
and Self::canonicalize are the only resolvers.
Sourcepub async fn metadata(
&self,
path: impl AsRef<Path>,
) -> Result<Metadata, ZeroFsError>
pub async fn metadata( &self, path: impl AsRef<Path>, ) -> Result<Metadata, ZeroFsError>
Like Self::stat but resolves symlinks (final AND intermediate
components) client-side (readlink + re-walk), capped at 40 hops.
Sourcepub async fn canonicalize(
&self,
path: impl AsRef<Path>,
) -> Result<PathBuf, ZeroFsError>
pub async fn canonicalize( &self, path: impl AsRef<Path>, ) -> Result<PathBuf, ZeroFsError>
Resolve every symlink in path (40-hop cap) and return the canonical
path, for use with any other method. Lossless: paths are bytes, so a
non-UTF-8 component survives the round trip.
Sourcepub async fn exists(&self, path: impl AsRef<Path>) -> Result<bool, ZeroFsError>
pub async fn exists(&self, path: impl AsRef<Path>) -> Result<bool, ZeroFsError>
True if the path exists (any file type, no symlink following);
NotFound becomes false.
Sourcepub async fn set_attr(
&self,
path: impl AsRef<Path>,
attrs: SetAttrs,
) -> Result<Metadata, ZeroFsError>
pub async fn set_attr( &self, path: impl AsRef<Path>, attrs: SetAttrs, ) -> Result<Metadata, ZeroFsError>
Apply any combination of metadata changes; returns post-change metadata.
Sourcepub async fn chmod(
&self,
path: impl AsRef<Path>,
mode: u32,
) -> Result<Metadata, ZeroFsError>
pub async fn chmod( &self, path: impl AsRef<Path>, mode: u32, ) -> Result<Metadata, ZeroFsError>
Change permission bits.
Sourcepub async fn chown(
&self,
path: impl AsRef<Path>,
uid: Option<u32>,
gid: Option<u32>,
) -> Result<Metadata, ZeroFsError>
pub async fn chown( &self, path: impl AsRef<Path>, uid: Option<u32>, gid: Option<u32>, ) -> Result<Metadata, ZeroFsError>
Change owner and/or group (None leaves a field untouched).
Sourcepub async fn truncate(
&self,
path: impl AsRef<Path>,
size: u64,
) -> Result<Metadata, ZeroFsError>
pub async fn truncate( &self, path: impl AsRef<Path>, size: u64, ) -> Result<Metadata, ZeroFsError>
Truncate or extend a file to size bytes.
Sourcepub async fn set_times(
&self,
path: impl AsRef<Path>,
atime: Option<SetTime>,
mtime: Option<SetTime>,
) -> Result<Metadata, ZeroFsError>
pub async fn set_times( &self, path: impl AsRef<Path>, atime: Option<SetTime>, mtime: Option<SetTime>, ) -> Result<Metadata, ZeroFsError>
Set access/modification times (utimens; None leaves a field untouched).
Sourcepub async fn statfs(&self) -> Result<StatFs, ZeroFsError>
pub async fn statfs(&self) -> Result<StatFs, ZeroFsError>
Filesystem-wide usage and limits.
Sourcepub async fn sync(&self) -> Result<(), ZeroFsError>
pub async fn sync(&self) -> Result<(), ZeroFsError>
Flush to durable (S3-backed) storage. On ZeroFS the server-side flush is filesystem-global, so this is the durability endpoint for write→rename sequences.
Sourcepub async fn create_dir(
&self,
path: impl AsRef<Path>,
mode: u32,
) -> Result<Metadata, ZeroFsError>
pub async fn create_dir( &self, path: impl AsRef<Path>, mode: u32, ) -> Result<Metadata, ZeroFsError>
Create a directory; the parent must exist.
Sourcepub async fn create_dir_all(
&self,
path: impl AsRef<Path>,
mode: u32,
) -> Result<(), ZeroFsError>
pub async fn create_dir_all( &self, path: impl AsRef<Path>, mode: u32, ) -> Result<(), ZeroFsError>
Create a directory and any missing ancestors.
Sourcepub async fn remove_file(
&self,
path: impl AsRef<Path>,
) -> Result<(), ZeroFsError>
pub async fn remove_file( &self, path: impl AsRef<Path>, ) -> Result<(), ZeroFsError>
Remove a file, symlink, or device node.
Sourcepub async fn remove_dir(
&self,
path: impl AsRef<Path>,
) -> Result<(), ZeroFsError>
pub async fn remove_dir( &self, path: impl AsRef<Path>, ) -> Result<(), ZeroFsError>
Remove an empty directory.
Sourcepub async fn remove_dir_all(
&self,
path: impl AsRef<Path>,
) -> Result<(), ZeroFsError>
pub async fn remove_dir_all( &self, path: impl AsRef<Path>, ) -> Result<(), ZeroFsError>
Remove a directory and all its contents, recursively (client-side walk, not atomic).
Sourcepub async fn rename(
&self,
from: impl AsRef<Path>,
to: impl AsRef<Path>,
) -> Result<(), ZeroFsError>
pub async fn rename( &self, from: impl AsRef<Path>, to: impl AsRef<Path>, ) -> Result<(), ZeroFsError>
Atomically rename/move within the filesystem; replaces an existing target.
Sourcepub async fn hard_link(
&self,
original: impl AsRef<Path>,
link: impl AsRef<Path>,
) -> Result<Metadata, ZeroFsError>
pub async fn hard_link( &self, original: impl AsRef<Path>, link: impl AsRef<Path>, ) -> Result<Metadata, ZeroFsError>
Create a hard link at link pointing to the inode of original.
Sourcepub async fn symlink(
&self,
target: impl AsRef<Path>,
link_path: impl AsRef<Path>,
) -> Result<Metadata, ZeroFsError>
pub async fn symlink( &self, target: impl AsRef<Path>, link_path: impl AsRef<Path>, ) -> Result<Metadata, ZeroFsError>
Create a symlink at link_path containing target (stored verbatim,
bytes included).
Sourcepub async fn read_link(
&self,
path: impl AsRef<Path>,
) -> Result<PathBuf, ZeroFsError>
pub async fn read_link( &self, path: impl AsRef<Path>, ) -> Result<PathBuf, ZeroFsError>
Read a symlink target. Lossless: the target is returned byte-for-byte.
Sourcepub async fn mknod(
&self,
path: impl AsRef<Path>,
kind: NodeKind,
mode: u32,
) -> Result<Metadata, ZeroFsError>
pub async fn mknod( &self, path: impl AsRef<Path>, kind: NodeKind, mode: u32, ) -> Result<Metadata, ZeroFsError>
Create a fifo, socket, or device node; mode carries permission bits
only; the type (and device numbers) come from kind.
Sourcepub async fn read_dir(
&self,
path: impl AsRef<Path>,
) -> Result<Vec<DirEntry>, ZeroFsError>
pub async fn read_dir( &self, path: impl AsRef<Path>, ) -> Result<Vec<DirEntry>, ZeroFsError>
List a whole directory (./.. excluded), with metadata inline via
readdirplus.
Sourcepub async fn open_dir(
&self,
path: impl AsRef<Path>,
) -> Result<Arc<Dir>, ZeroFsError>
pub async fn open_dir( &self, path: impl AsRef<Path>, ) -> Result<Arc<Dir>, ZeroFsError>
Open a directory for incremental listing and byte-exact child operations.
Sourcepub async fn open(
&self,
path: impl AsRef<Path>,
opts: OpenOptions,
) -> Result<Arc<File>, ZeroFsError>
pub async fn open( &self, path: impl AsRef<Path>, opts: OpenOptions, ) -> Result<Arc<File>, ZeroFsError>
Open (and optionally create) a file for positioned I/O.