pub struct VirtualRoot<Marker = ()> { /* private fields */ }Expand description
A user-facing virtual root that produces VirtualPath values.
Implementations§
Source§impl<Marker> VirtualRoot<Marker>
impl<Marker> VirtualRoot<Marker>
Sourcepub fn try_new<P: AsRef<Path>>(root_path: P) -> Result<Self>
pub fn try_new<P: AsRef<Path>>(root_path: P) -> Result<Self>
Creates a VirtualRoot from an existing directory.
Uses AsRef<Path> for maximum ergonomics, including direct TempDir support for clean shadowing patterns:
use strict_path::VirtualRoot;
let tmp_dir = tempfile::tempdir()?;
let tmp_dir = VirtualRoot::<()>::try_new(tmp_dir)?; // Clean variable shadowingSourcepub fn metadata(&self) -> Result<Metadata>
pub fn metadata(&self) -> Result<Metadata>
Returns filesystem metadata for the underlying root directory.
Sourcepub fn virtual_symlink(&self, link_path: &VirtualPath<Marker>) -> Result<()>
pub fn virtual_symlink(&self, link_path: &VirtualPath<Marker>) -> Result<()>
Creates a symbolic link at link_path that points to this VirtualRoot’s underlying directory.
Sourcepub fn virtual_hard_link(&self, link_path: &VirtualPath<Marker>) -> Result<()>
pub fn virtual_hard_link(&self, link_path: &VirtualPath<Marker>) -> Result<()>
Creates a hard link at link_path that points to this VirtualRoot’s underlying directory.
Sourcepub fn read_dir(&self) -> Result<ReadDir>
pub fn read_dir(&self) -> Result<ReadDir>
Reads the directory entries at the virtual root (like std::fs::read_dir).
This is intended for discovery. Prefer collecting each entry’s file name via
entry.file_name() and re-joining using virtual_join(...) (or strict_join(...)
after converting) before performing I/O on child paths.
Sourcepub fn remove_dir(&self) -> Result<()>
pub fn remove_dir(&self) -> Result<()>
Removes the underlying root directory (non-recursive).
Equivalent to std::fs::remove_dir(root). Fails if the directory is not empty.
Sourcepub fn remove_dir_all(&self) -> Result<()>
pub fn remove_dir_all(&self) -> Result<()>
Recursively removes the underlying root directory and all its contents.
Equivalent to std::fs::remove_dir_all(root).
Sourcepub fn try_new_create<P: AsRef<Path>>(root_path: P) -> Result<Self>
pub fn try_new_create<P: AsRef<Path>>(root_path: P) -> Result<Self>
Creates the directory if missing, then returns a VirtualRoot.
Uses AsRef<Path> for maximum ergonomics, including direct TempDir support for clean shadowing patterns:
use strict_path::VirtualRoot;
let tmp_dir = tempfile::tempdir()?;
let tmp_dir = VirtualRoot::<()>::try_new_create(tmp_dir)?; // Clean variable shadowingSourcepub fn virtual_join<P: AsRef<Path>>(
&self,
candidate_path: P,
) -> Result<VirtualPath<Marker>>
pub fn virtual_join<P: AsRef<Path>>( &self, candidate_path: P, ) -> Result<VirtualPath<Marker>>
Joins a path to this virtual root, producing a clamped VirtualPath.
Preserves the virtual root through clamping and validates against the restriction. May return an error if resolution (e.g., via symlinks) would escape the restriction.
Sourcepub fn interop_path(&self) -> &OsStr
pub fn interop_path(&self) -> &OsStr
Returns the virtual root path for interop with AsRef<Path> APIs.
This provides allocation-free, OS-native string access to the virtual root
for use with standard library APIs that accept AsRef<Path>.
Sourcepub fn as_unvirtual(&self) -> &PathBoundary<Marker>
pub fn as_unvirtual(&self) -> &PathBoundary<Marker>
Returns a reference to the underlying PathBoundary.
This allows access to path boundary-specific operations like strictpath_display()
while maintaining the borrowed relationship.
Sourcepub fn unvirtual(self) -> PathBoundary<Marker>
pub fn unvirtual(self) -> PathBoundary<Marker>
Consumes this VirtualRoot and returns the underlying PathBoundary.
This provides symmetry with PathBoundary::virtualize() and allows conversion
back to the path boundary representation when virtual semantics are no longer needed.
Trait Implementations§
Source§impl<Marker> AsRef<Path> for VirtualRoot<Marker>
impl<Marker> AsRef<Path> for VirtualRoot<Marker>
Source§impl<Marker: Clone> Clone for VirtualRoot<Marker>
impl<Marker: Clone> Clone for VirtualRoot<Marker>
Source§fn clone(&self) -> VirtualRoot<Marker>
fn clone(&self) -> VirtualRoot<Marker>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<Marker> Debug for VirtualRoot<Marker>
impl<Marker> Debug for VirtualRoot<Marker>
Source§impl<Marker> Display for VirtualRoot<Marker>
impl<Marker> Display for VirtualRoot<Marker>
Source§impl<Marker: Default> FromStr for VirtualRoot<Marker>
impl<Marker: Default> FromStr for VirtualRoot<Marker>
Source§fn from_str(path: &str) -> Result<Self, Self::Err>
fn from_str(path: &str) -> Result<Self, Self::Err>
Parse a VirtualRoot from a string path for universal ergonomics.
Creates the directory if it doesn’t exist, enabling seamless integration with any string-parsing context (clap, config files, environment variables, etc.):
let temp_dir = tempfile::tempdir()?;
let virtual_path = temp_dir.path().join("virtual_dir");
let vroot: VirtualRoot<()> = virtual_path.to_string_lossy().parse()?;
assert!(virtual_path.exists());