pub struct VirtualPath<Marker = ()> { /* private fields */ }Expand description
A user-facing path clamped to the virtual root path.
virtualpath_display() shows a rooted, forward-slashed path (e.g., "/a/b.txt").
Use virtual manipulation methods to compose paths while preserving clamping,
and convert to StrictPath with unvirtual() for system-facing I/O.
Implementations§
Source§impl<Marker> VirtualPath<Marker>
impl<Marker> VirtualPath<Marker>
Sourcepub fn with_root<P: AsRef<Path>>(root: P) -> Result<Self>
pub fn with_root<P: AsRef<Path>>(root: P) -> Result<Self>
Create the virtual root ("/") for the given filesystem root.
Prefer this ergonomic constructor when you want to start from the virtual root for a given filesystem directory.
Sourcepub fn with_root_create<P: AsRef<Path>>(root: P) -> Result<Self>
pub fn with_root_create<P: AsRef<Path>>(root: P) -> Result<Self>
Create the virtual root ("/"), creating the filesystem root if missing.
Creates the backing directory if needed.
Sourcepub fn unvirtual(self) -> StrictPath<Marker>
pub fn unvirtual(self) -> StrictPath<Marker>
Converts this VirtualPath back into a system-facing StrictPath.
Sourcepub fn try_into_root(self) -> VirtualRoot<Marker>
pub fn try_into_root(self) -> VirtualRoot<Marker>
Consumes this VirtualPath and returns the VirtualRoot for its boundary.
Equivalent to self.unvirtual().try_into_boundary().virtualize() but without
requiring intermediate variables. Does not create any directories.
Sourcepub fn try_into_root_create(self) -> VirtualRoot<Marker>
pub fn try_into_root_create(self) -> VirtualRoot<Marker>
Consumes this VirtualPath and returns a VirtualRoot, creating the
underlying directory if it does not exist.
If the boundary directory is somehow missing, it will be created before
producing the VirtualRoot.
Sourcepub fn as_unvirtual(&self) -> &StrictPath<Marker>
pub fn as_unvirtual(&self) -> &StrictPath<Marker>
Borrows the underlying system-facing StrictPath (no allocation).
Use this to pass a &VirtualPath to APIs that accept &StrictPath.
Sourcepub fn interop_path(&self) -> &OsStr
pub fn interop_path(&self) -> &OsStr
Returns the underlying system path as &OsStr for AsRef<Path> interop.
Sourcepub fn virtual_join<P: AsRef<Path>>(&self, path: P) -> Result<Self>
pub fn virtual_join<P: AsRef<Path>>(&self, path: P) -> Result<Self>
Safely joins a virtual path segment (virtual semantics) and re-validates.
Sourcepub fn virtualpath_parent(&self) -> Result<Option<Self>>
pub fn virtualpath_parent(&self) -> Result<Option<Self>>
Returns the parent virtual path, or None if at the virtual root.
Sourcepub fn virtualpath_with_file_name<S: AsRef<OsStr>>(
&self,
file_name: S,
) -> Result<Self>
pub fn virtualpath_with_file_name<S: AsRef<OsStr>>( &self, file_name: S, ) -> Result<Self>
Returns a new VirtualPath with the file name changed, preserving clamping.
Sourcepub fn virtualpath_with_extension<S: AsRef<OsStr>>(
&self,
extension: S,
) -> Result<Self>
pub fn virtualpath_with_extension<S: AsRef<OsStr>>( &self, extension: S, ) -> Result<Self>
Returns a new VirtualPath with the extension changed, preserving clamping.
Sourcepub fn virtualpath_file_name(&self) -> Option<&OsStr>
pub fn virtualpath_file_name(&self) -> Option<&OsStr>
Returns the file name component of the virtual path, if any.
Sourcepub fn virtualpath_file_stem(&self) -> Option<&OsStr>
pub fn virtualpath_file_stem(&self) -> Option<&OsStr>
Returns the file stem of the virtual path, if any.
Sourcepub fn virtualpath_extension(&self) -> Option<&OsStr>
pub fn virtualpath_extension(&self) -> Option<&OsStr>
Returns the extension of the virtual path, if any.
Sourcepub fn virtualpath_starts_with<P: AsRef<Path>>(&self, p: P) -> bool
pub fn virtualpath_starts_with<P: AsRef<Path>>(&self, p: P) -> bool
Returns true if the virtual path starts with the given prefix (virtual semantics).
Sourcepub fn virtualpath_ends_with<P: AsRef<Path>>(&self, p: P) -> bool
pub fn virtualpath_ends_with<P: AsRef<Path>>(&self, p: P) -> bool
Returns true if the virtual path ends with the given suffix (virtual semantics).
Sourcepub fn virtualpath_display(&self) -> VirtualPathDisplay<'_, Marker>
pub fn virtualpath_display(&self) -> VirtualPathDisplay<'_, Marker>
Returns a Display wrapper that shows a rooted virtual path (e.g., "/a/b.txt").
Sourcepub fn read_to_string(&self) -> Result<String>
pub fn read_to_string(&self) -> Result<String>
Reads the file contents as String from the underlying system path.
Sourcepub fn read_bytes(&self) -> Result<Vec<u8>>
👎Deprecated since 0.1.0-alpha.5: Use read() instead
pub fn read_bytes(&self) -> Result<Vec<u8>>
Reads the file contents as raw bytes from the underlying system path.
Sourcepub fn write_bytes(&self, data: &[u8]) -> Result<()>
👎Deprecated since 0.1.0-alpha.5: Use write(…) instead
pub fn write_bytes(&self, data: &[u8]) -> Result<()>
Writes raw bytes to the underlying system path.
Sourcepub fn write_string(&self, data: &str) -> Result<()>
👎Deprecated since 0.1.0-alpha.5: Use write(…) instead
pub fn write_string(&self, data: &str) -> Result<()>
Writes a UTF-8 string to the underlying system path.
Sourcepub fn read(&self) -> Result<Vec<u8>>
pub fn read(&self) -> Result<Vec<u8>>
Reads the file contents as raw bytes (replacement for read_bytes).
Sourcepub fn read_dir(&self) -> Result<ReadDir>
pub fn read_dir(&self) -> Result<ReadDir>
Reads the directory entries at the underlying system path (like std::fs::read_dir).
This is intended for discovery in the virtual space. Collect each entry’s file name via
entry.file_name() and re‑join with virtual_join(...) to preserve clamping before I/O.
Sourcepub fn write<C: AsRef<[u8]>>(&self, contents: C) -> Result<()>
pub fn write<C: AsRef<[u8]>>(&self, contents: C) -> Result<()>
Writes data to the underlying system path. Accepts &str, String, &[u8], Vec<u8], etc.
Sourcepub fn create_dir_all(&self) -> Result<()>
pub fn create_dir_all(&self) -> Result<()>
Creates all directories in the underlying system path if missing.
Sourcepub fn create_dir(&self) -> Result<()>
pub fn create_dir(&self) -> Result<()>
Creates the directory at this virtual location (non-recursive).
Mirrors std::fs::create_dir and fails if the parent does not exist.
Sourcepub fn create_parent_dir(&self) -> Result<()>
pub fn create_parent_dir(&self) -> Result<()>
Creates only the immediate parent directory of this virtual path (non-recursive).
Acts in the virtual dimension: the parent is derived via virtualpath_parent()
and then created on the underlying system path. Returns Ok(()) at virtual root.
Sourcepub fn create_parent_dir_all(&self) -> Result<()>
pub fn create_parent_dir_all(&self) -> Result<()>
Recursively creates all missing directories up to the immediate parent of this virtual path.
Acts in the virtual dimension; returns Ok(()) at virtual root.
Sourcepub fn remove_file(&self) -> Result<()>
pub fn remove_file(&self) -> Result<()>
Removes the file at the underlying system path.
Sourcepub fn remove_dir(&self) -> Result<()>
pub fn remove_dir(&self) -> Result<()>
Removes the directory at the underlying system path.
Sourcepub fn remove_dir_all(&self) -> Result<()>
pub fn remove_dir_all(&self) -> Result<()>
Recursively removes the directory and its contents at the underlying system path.
Sourcepub fn virtual_rename<P: AsRef<Path>>(&self, dest: P) -> Result<Self>
pub fn virtual_rename<P: AsRef<Path>>(&self, dest: P) -> Result<Self>
Renames or moves this virtual path to a new location within the same virtual root.
Destination paths are resolved in virtual space:
- Relative inputs are interpreted as siblings (resolved against the virtual parent).
- Absolute virtual inputs are treated as requests from the virtual root.
Clamping and boundary checks are enforced by virtual joins. No parent directories are
created implicitly; call create_parent_dir_all() beforehand if needed.
Sourcepub fn virtual_copy<P: AsRef<Path>>(&self, dest: P) -> Result<Self>
pub fn virtual_copy<P: AsRef<Path>>(&self, dest: P) -> Result<Self>
Copies this virtual path to a new location within the same virtual root.
Destination paths are resolved in virtual space:
- Relative inputs are interpreted as siblings (resolved against the virtual parent).
- Absolute virtual inputs are treated as requests from the virtual root.
Clamping and boundary checks are enforced by virtual joins. No parent directories are
created implicitly; call create_parent_dir_all() beforehand if needed. Returns the
destination VirtualPath on success.
Trait Implementations§
Source§impl<Marker: Clone> Clone for VirtualPath<Marker>
impl<Marker: Clone> Clone for VirtualPath<Marker>
Source§fn clone(&self) -> VirtualPath<Marker>
fn clone(&self) -> VirtualPath<Marker>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more