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"));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
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<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> ⓘ
Converts
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> ⓘ
Converts
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