pub struct SafePath { /* private fields */ }
Expand description
Data-only type for safe path handling.
Centralized under crate::types
for cross-layer reuse.
Implementations§
Source§impl SafePath
impl SafePath
Sourcepub fn from_rooted(root: &Path, candidate: &Path) -> Result<Self>
pub fn from_rooted(root: &Path, candidate: &Path) -> Result<Self>
Creates a new SafePath
from a root and candidate path.
This function ensures that the candidate path is within the root path and does not contain any unsafe components like dotdot (..).
§Arguments
root
- The root path that the candidate should be withincandidate
- The path to check and make safe
§Returns
Result<Self>
- ASafePath
if the candidate is valid, or an error otherwise
§Errors
Returns an error if the root path is not absolute, if the candidate path escapes the root, or if the candidate path contains unsafe components like dotdot (..).
§Panics
Panics when root
is not absolute. This mirrors historical semantics and
preserves SPEC/BDD expectations for construction invariants in tests.
§Example
use switchyard::types::safepath::SafePath;
let td = tempfile::tempdir()?;
let root = td.path();
std::fs::create_dir_all(root.join("usr/bin"))?;
let sp = SafePath::from_rooted(root, &root.join("usr/bin/ls"))?;
assert!(sp.as_path().starts_with(root));
Trait Implementations§
impl Eq for SafePath
impl StructuralPartialEq for SafePath
Auto Trait Implementations§
impl Freeze for SafePath
impl RefUnwindSafe for SafePath
impl Send for SafePath
impl Sync for SafePath
impl Unpin for SafePath
impl UnwindSafe for SafePath
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.