Skip to main content

Mount

Trait Mount 

Source
pub trait Mount: Send + Sync {
    // Required method
    fn mountpoint(&self) -> &Path;

    // Provided methods
    fn url(&self) -> Option<String> { ... }
    fn host_path(&self, path: &Path) -> PathBuf { ... }
}
Expand description

A filesystem the operating system has mounted, and a path where it will answer.

FileSystem and Directory describe a tree inside this process; nothing outside can see them. A Mount is the state of having been mounted: a binding’s guard, or a path the host attached. Its one fact is mountpoint, a path any process on this host can open, which is how anything outside this library (a guest included) reads a virtx tree.

§The tree is there for as long as the value is

That is the whole contract, and it is a lower bound, not a lifecycle. What happens after the value goes is the implementor’s business (a guard unmounts, a temporary directory is removed, a host directory stays) and is invisible through this trait. A guard meets the bound by RAII: try_new mounts, Drop unmounts, and there is no unmount to forget or call twice. To outlive one holder, share it (Arc) rather than leak it.

Guard-specific API such as join consumes the guard, so it cannot be on a dyn Mount.

A signal runs no destructor; unmount_on_signal and reclaim_abandoned cover that, deliberately not on this trait.

Send + Sync because the holder is usually a task that keeps it across awaits and hands out &self meanwhile.

Required Methods§

Source

fn mountpoint(&self) -> &Path

Where this is mounted — the directory a kernel now answers for.

Provided Methods§

Source

fn url(&self) -> Option<String>

This mount as a URL, e.g. file:///srv/project: the spelling given to anything outside the process, so it can be named alongside trees that are not local directories.

Not percent-encoded, so a reader need not decode it back into a path.

None unless the mount point is an absolute UTF-8 path: a relative path after file:// reads as a host, and a lossy name would look valid but name another directory.

Source

fn host_path(&self, path: &Path) -> PathBuf

Where path, relative to the mounted tree’s root, is on this host.

path must be relative: Path::join with an absolute path discards the mountpoint.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Mount for PathBuf

A directory the host already mounted is a mount, and its own mount point.

Nothing here takes it down; the tree outlives every holder. This lets a plain directory (./out, a caller’s temp dir) stand in wherever a mount is expected.

Not canonicalized, since consumers report the spelling back and macOS would answer a temp dir through /private. Not required to be absolute: only url needs that, and it answers None.

Source§

fn mountpoint(&self) -> &Path

Source§

impl<T: Mount + ?Sized> Mount for Arc<T>

A shared mount, including Arc<dyn Mount>. The tree stays up until the last holder drops.

Source§

fn mountpoint(&self) -> &Path

Source§

impl<T: Mount + ?Sized> Mount for Box<T>

A boxed mount, including Box<dyn Mount> for a binding chosen at runtime.

Source§

fn mountpoint(&self) -> &Path

Implementors§