pub trait Backend: Send + Sync {
// Required methods
fn caps(&self) -> Caps;
fn walk(&self, path: &NsPath) -> NsResult<Vec<Entry>>;
fn read(&self, path: &NsPath, max: u64) -> NsResult<(Vec<u8>, Version)>;
fn stat(&self, path: &NsPath) -> NsResult<Stat>;
fn write(
&self,
path: &NsPath,
op: WriteOp,
data: &[u8],
if_version: Option<&Version>,
) -> NsResult<Version>;
fn watch(&self, path: &NsPath, opts: WatchOpts) -> NsResult<Watch>;
// Provided method
fn root_identity(&self) -> Option<(u64, u64)> { ... }
}Expand description
A mount: a file tree behind one root, addressed by path.
Implementations must enforce the portable name grammar (it comes for free from NsPath, and any name read back
from the backing store goes through validate_name), must refuse to create a name that
case-folds to an existing sibling (CaseCollision), and must return Unsupported for anything their Caps say
they cannot do. The conformance suite checks all of it.
This trait is not frozen (see the module docs). New methods arrive with a default body, so an existing
implementation keeps compiling and behaves as if the new capability were absent; Backend::root_identity was added
that way. A method without a default would be a breaking change and a minor bump while pre-1.0.
Required Methods§
Sourcefn walk(&self, path: &NsPath) -> NsResult<Vec<Entry>>
fn walk(&self, path: &NsPath) -> NsResult<Vec<Entry>>
List a directory, sorted by name in UTF-8 byte order (so B sorts before a, and z before é), the whole
directory at once. Only entries that are addressable are listed: names outside the grammar, temporary files, and
anything that is neither a regular file nor a directory are omitted.
The order is part of the contract (a caller may merge two listings, or page through one by name). Paging of walk
itself (a cursor, a page size) is deferred until a read-only content-addressed mount has exercised the trait;
it will be added as a separate, additive call.
Sourcefn read(&self, path: &NsPath, max: u64) -> NsResult<(Vec<u8>, Version)>
fn read(&self, path: &NsPath, max: u64) -> NsResult<(Vec<u8>, Version)>
Read a whole file. If it is larger than max bytes the result is TooLarge and nothing is returned; the
backend reads at most max + 1 bytes to find that out.
Sourcefn stat(&self, path: &NsPath) -> NsResult<Stat>
fn stat(&self, path: &NsPath) -> NsResult<Stat>
The manifest verb. Works on files and directories (and on /).
Sourcefn write(
&self,
path: &NsPath,
op: WriteOp,
data: &[u8],
if_version: Option<&Version>,
) -> NsResult<Version>
fn write( &self, path: &NsPath, op: WriteOp, data: &[u8], if_version: Option<&Version>, ) -> NsResult<Version>
Apply one WriteOp. if_version: if Some, the target must exist (NotFound otherwise) and its current
version must equal it (VersionMismatch otherwise); it is meaningless for CreateExclusive and MakeDir
(InvalidInput). Exact where Caps::exact_if_version, otherwise check-then-act.
Returns the version of the entry after the op (for Remove, the version it had).
Provided Methods§
Sourcefn root_identity(&self) -> Option<(u64, u64)>
fn root_identity(&self) -> Option<(u64, u64)>
Which host directory this mount is rooted at, as (device, inode) (Windows: volume serial number and file
index), or None if the backend is not over a host directory or cannot tell. Default None.
NamespaceBuilder::build uses it for one check: two mounts that report the
same identity are refused (InvalidInput(DuplicateRoot)), because access is enforced per mount and two mounts of
one directory would let a write through one change what the other, perhaps read-only, mount reads.
What this does not detect: a directory mounted together with an ancestor or a descendant of it (it needs
host paths, which the Kit does not keep), two mounts of a backend that returns None, or an identity that
differs because the same directory was reached through two different hard-linked or bind-mounted views. Only a
backend over a real host directory should return Some; its value must not change for the life of the backend.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".