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.
Sugar for VirtualRoot::try_new(root)?.virtual_join("").
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.
Sugar for VirtualRoot::try_new_create(root)?.virtual_join("").
Sourcepub fn unvirtual(self) -> StrictPath<Marker>
pub fn unvirtual(self) -> StrictPath<Marker>
Converts this VirtualPath back into a system-facing StrictPath.
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>>
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<()>
pub fn write_bytes(&self, data: &[u8]) -> Result<()>
Writes raw bytes to the underlying system path.
Sourcepub fn write_string(&self, data: &str) -> Result<()>
pub fn write_string(&self, data: &str) -> Result<()>
Writes a UTF-8 string to the underlying system path.
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.
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