pub struct SafePath(/* private fields */);Expand description
A validated, safe filesystem path.
Rejects .. components, absolute paths, and null bytes.
Use this for all externally-supplied file path arguments.
Implementations§
Source§impl SafePath
impl SafePath
Sourcepub fn new(path: impl AsRef<Path>) -> Result<Self>
pub fn new(path: impl AsRef<Path>) -> Result<Self>
Creates a new SafePath from a relative path string.
§Errors
Returns CoreError::Path if:
- The path contains
..components - The path is absolute
- The path contains null bytes
- The path contains a Windows reserved device name
- The path contains invalid characters (e.g.,
:for ADS) - The path contains dangerous Unicode bidi control characters
- Any path component exceeds 255 bytes
§Examples
use gitflow_core::SafePath;
let path = SafePath::new("foo/bar.txt")?;
assert_eq!(path.as_path(), std::path::Path::new("foo/bar.txt"));Sourcepub fn new_allow_absolute(path: impl AsRef<Path>) -> Result<Self>
pub fn new_allow_absolute(path: impl AsRef<Path>) -> Result<Self>
Creates a new SafePath from a path string, permitting absolute paths.
Use this only for arguments where an absolute path is a legitimate,
intentional input from the invoking user (e.g. a CLI --path flag
naming an install directory), not for path fragments that get joined
onto a trusted base directory.
All other SafePath::new checks still apply: .. traversal, null
bytes, reserved device names, invalid characters, dangerous Unicode
bidi control characters, and per-component length are still rejected.
§Errors
See SafePath::new for the full list of rejected inputs (absolute
paths excepted).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SafePath
impl RefUnwindSafe for SafePath
impl Send for SafePath
impl Sync for SafePath
impl Unpin for SafePath
impl UnsafeUnpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more