Skip to main content

Client

Struct Client 

Source
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

Source

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://...".

Source

pub async fn connect_with( target: &str, opts: ConnectOptions, ) -> Result<Arc<Client>, ZeroFsError>

Connect with explicit identity, timeout, and tuning.

Source

pub async fn connect_multi( targets: &[String], ) -> Result<Arc<Client>, ZeroFsError>

Connect across a target set, probing for the serving leader on reconnect.

Source

pub fn capabilities(&self) -> Capabilities

Negotiated properties, fixed for the lifetime of this logical session.

Source

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.

Source

pub fn traffic_stats(&self) -> TrafficStats

Cumulative 9P wire traffic for this client, including reconnects.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn chmod( &self, path: impl AsRef<Path>, mode: u32, ) -> Result<Metadata, ZeroFsError>

Change permission bits.

Source

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).

Source

pub async fn truncate( &self, path: impl AsRef<Path>, size: u64, ) -> Result<Metadata, ZeroFsError>

Truncate or extend a file to size bytes.

Source

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).

Source

pub async fn statfs(&self) -> Result<StatFs, ZeroFsError>

Filesystem-wide usage and limits.

Source

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.

Source

pub async fn create_dir( &self, path: impl AsRef<Path>, mode: u32, ) -> Result<Metadata, ZeroFsError>

Create a directory; the parent must exist.

Source

pub async fn create_dir_all( &self, path: impl AsRef<Path>, mode: u32, ) -> Result<(), ZeroFsError>

Create a directory and any missing ancestors.

Source

pub async fn remove_file( &self, path: impl AsRef<Path>, ) -> Result<(), ZeroFsError>

Remove a file, symlink, or device node.

Source

pub async fn remove_dir( &self, path: impl AsRef<Path>, ) -> Result<(), ZeroFsError>

Remove an empty directory.

Source

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).

Source

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.

Create a hard link at link pointing to the inode of original.

Create a symlink at link_path containing target (stored verbatim, bytes included).

Read a symlink target. Lossless: the target is returned byte-for-byte.

Source

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.

Source

pub async fn read_dir( &self, path: impl AsRef<Path>, ) -> Result<Vec<DirEntry>, ZeroFsError>

List a whole directory (./.. excluded), with metadata inline via readdirplus.

Source

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.

Source

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.

Source

pub async fn create( &self, path: impl AsRef<Path>, ) -> Result<Arc<File>, ZeroFsError>

Shorthand: open read-write with create+truncate, mode 0o644.

Trait Implementations§

Source§

impl Debug for Client

Source§

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

Formats the value using the given formatter. 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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more