pub struct PathBoundary<Marker = ()> { /* private fields */ }Expand description
A path boundary that serves as the secure foundation for validated path operations.
SUMMARY:
Represent the trusted filesystem boundary directory for all strict and virtual path
operations. All StrictPath/VirtualPath values derived from a PathBoundary are
guaranteed to remain within this boundary.
EXAMPLE:
let boundary = PathBoundary::<()>::try_new_create("./data")?;
let file = boundary.strict_join("logs/app.log")?;
println!("{}", file.strictpath_display());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 anchored at restriction_path (which must already exist and be a directory).
SUMMARY: Create a boundary anchored at an existing directory (must exist and be a directory).
PARAMETERS:
restriction_path(AsRef<Path>): Existing directory to anchor the boundary.
RETURNS:
Result<PathBoundary<Marker>>: New boundary whose directory is canonicalized and verified to exist.
ERRORS:
StrictPathError::InvalidRestriction: Boundary directory is missing, not a directory, or cannot be canonicalized.
EXAMPLE:
use strict_path::PathBoundary;
let boundary = PathBoundary::<()>::try_new("./data")?;Sourcepub fn try_new_create<P: AsRef<Path>>(boundary_dir: P) -> Result<Self>
pub fn try_new_create<P: AsRef<Path>>(boundary_dir: P) -> Result<Self>
Creates the directory if missing, then constructs a new PathBoundary.
SUMMARY: Ensure the boundary directory exists (create if missing) and construct a new boundary.
PARAMETERS:
boundary_dir(AsRef<Path>): Directory to create if needed and use as the boundary directory.
RETURNS:
Result<PathBoundary<Marker>>: New boundary anchored atboundary_dir.
ERRORS:
StrictPathError::InvalidRestriction: Directory creation/canonicalization fails.
EXAMPLE:
use strict_path::PathBoundary;
let boundary = PathBoundary::<()>::try_new_create("./data")?;Sourcepub 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>>
SUMMARY:
Join a candidate path to the boundary and return a validated StrictPath.
PARAMETERS:
candidate_path(AsRef<Path>): Absolute or relative path to validate within this boundary.
RETURNS:
Result<StrictPath<Marker>>: Canonicalized, boundary-checked path.
ERRORS:
StrictPathError::PathResolutionError,StrictPathError::PathEscapesBoundary.
Sourcepub fn change_marker<NewMarker>(self) -> PathBoundary<NewMarker>
pub fn change_marker<NewMarker>(self) -> PathBoundary<NewMarker>
SUMMARY: Consume this boundary and substitute a new marker type.
DETAILS:
Mirrors crate::StrictPath::change_marker and crate::VirtualPath::change_marker, enabling
marker transformation after authorization checks. Use this when encoding proven
authorization into the type system (e.g., after validating a user’s permissions).
The consumption makes marker changes explicit during code review.
PARAMETERS:
NewMarker(type parameter): Marker to associate with the boundary.
RETURNS:
PathBoundary<NewMarker>: Same underlying boundary, rebranded withNewMarker.
EXAMPLE:
struct ReadOnly;
struct ReadWrite;
let read_boundary: PathBoundary<ReadOnly> = PathBoundary::try_new_create("./data")?;
// After authorization check...
let write_boundary: PathBoundary<ReadWrite> = read_boundary.change_marker();Sourcepub fn into_strictpath(self) -> Result<StrictPath<Marker>>
pub fn into_strictpath(self) -> Result<StrictPath<Marker>>
SUMMARY:
Consume this boundary and return a StrictPath anchored at the boundary directory.
PARAMETERS:
- none
RETURNS:
Result<StrictPath<Marker>>: Strict path for the canonicalized boundary directory.
ERRORS:
StrictPathError::PathResolutionError: Canonicalization fails (directory removed or inaccessible).StrictPathError::PathEscapesBoundary: Guard against race conditions that move the directory.
EXAMPLE:
let boundary: PathBoundary = PathBoundary::try_new_create("./data")?;
let boundary_path: StrictPath = boundary.into_strictpath()?;
assert!(boundary_path.is_dir());Sourcepub fn exists(&self) -> bool
pub fn exists(&self) -> bool
Returns true if the PathBoundary directory 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
SUMMARY:
Return the boundary directory path as &OsStr for unavoidable third-party AsRef<Path> interop (no allocation).
Sourcepub fn strictpath_display(&self) -> Display<'_>
pub fn strictpath_display(&self) -> Display<'_>
Returns a Display wrapper that shows the PathBoundary directory system path.
Sourcepub fn metadata(&self) -> Result<Metadata>
pub fn metadata(&self) -> Result<Metadata>
SUMMARY: Return filesystem metadata for the boundary directory.
Sourcepub fn strict_symlink<P: AsRef<Path>>(&self, link_path: P) -> Result<()>
pub fn strict_symlink<P: AsRef<Path>>(&self, link_path: P) -> Result<()>
SUMMARY:
Create a symbolic link at link_path pointing to this boundary’s directory.
PARAMETERS:
link_path(impl AsRef<Path>): Destination for the symlink, within the same boundary.
RETURNS:
io::Result<()>: Mirrors std semantics.
Sourcepub fn strict_hard_link<P: AsRef<Path>>(&self, link_path: P) -> Result<()>
pub fn strict_hard_link<P: AsRef<Path>>(&self, link_path: P) -> Result<()>
SUMMARY:
Create a hard link at link_path pointing to this boundary’s directory.
PARAMETERS and RETURNS mirror strict_symlink.
Sourcepub fn read_dir(&self) -> Result<ReadDir>
pub fn read_dir(&self) -> Result<ReadDir>
SUMMARY: Read directory entries under the boundary directory (discovery only).
Sourcepub fn remove_dir(&self) -> Result<()>
pub fn remove_dir(&self) -> Result<()>
SUMMARY: Remove the boundary directory (non-recursive); fails if not empty.
Sourcepub fn remove_dir_all(&self) -> Result<()>
pub fn remove_dir_all(&self) -> Result<()>
SUMMARY: Recursively remove the boundary directory and its contents.
Sourcepub fn virtualize(self) -> VirtualRoot<Marker>
pub fn virtualize(self) -> VirtualRoot<Marker>
SUMMARY:
Convert this boundary into a VirtualRoot for virtual path operations.
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 boundary: PathBoundary<()> = "./data".parse()?;
assert!(boundary.exists());Source§type Err = StrictPathError
type Err = StrictPathError
Source§impl<Marker> Hash for PathBoundary<Marker>
impl<Marker> Hash for PathBoundary<Marker>
Source§impl<Marker> Ord for PathBoundary<Marker>
impl<Marker> Ord for PathBoundary<Marker>
Source§impl<Marker> PartialEq<&Path> for PathBoundary<Marker>
impl<Marker> PartialEq<&Path> for PathBoundary<Marker>
Source§impl<Marker> PartialEq<Path> for PathBoundary<Marker>
impl<Marker> PartialEq<Path> for PathBoundary<Marker>
Source§impl<M1, M2> PartialEq<PathBoundary<M2>> for PathBoundary<M1>
impl<M1, M2> PartialEq<PathBoundary<M2>> for PathBoundary<M1>
Source§impl<M1, M2> PartialEq<PathBoundary<M2>> for VirtualRoot<M1>
impl<M1, M2> PartialEq<PathBoundary<M2>> for VirtualRoot<M1>
Source§impl<Marker> PartialEq<PathBuf> for PathBoundary<Marker>
impl<Marker> PartialEq<PathBuf> for PathBoundary<Marker>
Source§impl<M1, M2> PartialEq<VirtualRoot<M2>> for PathBoundary<M1>
Available on crate feature virtual-path only.
impl<M1, M2> PartialEq<VirtualRoot<M2>> for PathBoundary<M1>
virtual-path only.