pub struct PathBoundary<Marker = ()> { /* private fields */ }Expand description
A path boundary that serves as the secure foundation for validated path operations.
PathBoundary represents the trusted starting point (like /home/users/alice) from which
all path operations begin. When you call path_boundary.strict_join("documents/file.txt"),
you’re building outward from this secure boundary with validated path construction.
Implementations§
Source§impl<Marker> PathBoundary<Marker>
impl<Marker> PathBoundary<Marker>
Sourcepub fn try_new<P: AsRef<Path>>(restriction_path: P) -> Result<Self>
pub fn try_new<P: AsRef<Path>>(restriction_path: P) -> Result<Self>
Creates a new PathBoundary rooted at restriction_path (which must already exist and be a directory).
Uses AsRef<Path> for maximum ergonomics, including direct TempDir support for clean shadowing patterns:
use strict_path::PathBoundary;
let tmp_dir = tempfile::tempdir()?;
let tmp_dir = PathBoundary::<()>::try_new(tmp_dir)?; // Clean variable shadowingSourcepub fn try_new_create<P: AsRef<Path>>(root: P) -> Result<Self>
pub fn try_new_create<P: AsRef<Path>>(root: P) -> Result<Self>
Creates the directory if missing, then constructs a new PathBoundary.
Uses AsRef<Path> for maximum ergonomics, including direct TempDir support for clean shadowing patterns:
use strict_path::PathBoundary;
let tmp_dir = tempfile::tempdir()?;
let tmp_dir = PathBoundary::<()>::try_new_create(tmp_dir)?; // Clean variable shadowingSourcepub fn strict_join(
&self,
candidate_path: impl AsRef<Path>,
) -> Result<StrictPath<Marker>>
pub fn strict_join( &self, candidate_path: impl AsRef<Path>, ) -> Result<StrictPath<Marker>>
Joins a path to this restrictor root and validates it remains within the restriction boundary.
Accepts absolute or relative inputs; ensures the resulting path remains within the restriction.
Sourcepub fn exists(&self) -> bool
pub fn exists(&self) -> bool
Returns true if the PathBoundary root exists.
This is always true for a constructed PathBoundary, but we query the filesystem for robustness.
Sourcepub fn interop_path(&self) -> &OsStr
pub fn interop_path(&self) -> &OsStr
Returns the PathBoundary root path for interop with AsRef<Path> APIs.
This provides allocation-free, OS-native string access to the PathBoundary root
for use with standard library APIs that accept AsRef<Path>.
Sourcepub fn strictpath_display(&self) -> Display<'_>
pub fn strictpath_display(&self) -> Display<'_>
Returns a Display wrapper that shows the PathBoundary root system path.
Sourcepub fn metadata(&self) -> Result<Metadata>
pub fn metadata(&self) -> Result<Metadata>
Returns filesystem metadata for the PathBoundary root path.
Sourcepub fn strict_symlink(&self, link_path: &StrictPath<Marker>) -> Result<()>
pub fn strict_symlink(&self, link_path: &StrictPath<Marker>) -> Result<()>
Creates a symbolic link at link_path that points to this PathBoundary’s root.
Sourcepub fn strict_hard_link(&self, link_path: &StrictPath<Marker>) -> Result<()>
pub fn strict_hard_link(&self, link_path: &StrictPath<Marker>) -> Result<()>
Creates a hard link at link_path that points to this PathBoundary’s root.
Sourcepub fn read_dir(&self) -> Result<ReadDir>
pub fn read_dir(&self) -> Result<ReadDir>
Reads the directory entries under this PathBoundary root (like std::fs::read_dir).
This is intended for discovery. Prefer collecting entry names and joining via
strict_join/virtual_join before performing I/O.
Sourcepub fn remove_dir(&self) -> Result<()>
pub fn remove_dir(&self) -> Result<()>
Removes this PathBoundary 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 this PathBoundary root directory and all its contents.
Equivalent to std::fs::remove_dir_all(root).
Sourcepub fn virtualize(self) -> VirtualRoot<Marker>
pub fn virtualize(self) -> VirtualRoot<Marker>
Converts this PathBoundary into a VirtualRoot.
This creates a virtual root view of the PathBoundary, allowing virtual path operations that treat the PathBoundary root as the virtual filesystem root “/”.
Trait Implementations§
Source§impl<Marker> AsRef<Path> for PathBoundary<Marker>
impl<Marker> AsRef<Path> for PathBoundary<Marker>
Source§impl<Marker> Clone for PathBoundary<Marker>
impl<Marker> Clone for PathBoundary<Marker>
Source§impl<Marker> Debug for PathBoundary<Marker>
impl<Marker> Debug for PathBoundary<Marker>
Source§impl<Marker: Default> FromStr for PathBoundary<Marker>
impl<Marker: Default> FromStr for PathBoundary<Marker>
Source§fn from_str(path: &str) -> Result<Self, Self::Err>
fn from_str(path: &str) -> Result<Self, Self::Err>
Parse a PathBoundary 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 safe_path = temp_dir.path().join("safe_dir");
let boundary: PathBoundary<()> = safe_path.to_string_lossy().parse()?;
assert!(safe_path.exists());