pub struct NsPath(/* private fields */);Expand description
A validated namespace path: absolute, /-separated, every component inside the portable name grammar. See the
module docs for the grammar.
Holding an NsPath is proof the grammar was checked, so a backend does not re-parse strings and cannot be handed a
.. or a host path by construction.
Implementations§
Source§impl NsPath
impl NsPath
Sourcepub fn parse(input: &str) -> Result<Self, NsError>
pub fn parse(input: &str) -> Result<Self, NsError>
Validate and wrap a namespace path.
use storage_kit::ns::{NsPath, NsErrorKind, PathReason};
assert!(NsPath::parse("/config/apps.toml").is_ok());
let err = NsPath::parse("/config/../etc").unwrap_err();
assert_eq!(err.kind(), NsErrorKind::InvalidPath(PathReason::DotDotComponent));Sourcepub fn join(&self, relative: &str) -> Result<NsPath, NsError>
pub fn join(&self, relative: &str) -> Result<NsPath, NsError>
Append a relative path (name or a/b), validating every component.
A leading / is refused (it reads as an empty first component): to combine two absolute namespace paths use
NsPath::rebase.
Sourcepub fn components(&self) -> impl DoubleEndedIterator<Item = &str> + Clone
pub fn components(&self) -> impl DoubleEndedIterator<Item = &str> + Clone
The components, in order. Empty for the root.
Sourcepub fn starts_with(&self, base: &NsPath) -> bool
pub fn starts_with(&self, base: &NsPath) -> bool
True if base is this path or one of its ancestors, compared by whole components (/ab does not start with
/a). Every path starts with the root.
Sourcepub fn strip_prefix(&self, base: &NsPath) -> Option<NsPath>
pub fn strip_prefix(&self, base: &NsPath) -> Option<NsPath>
The path below base, re-rooted at /: /a/b/c stripped of /a is /b/c; stripped of itself it is /.
None if base is not a prefix. This is how a mount-relative path is derived.
Trait Implementations§
impl Eq for NsPath
Source§impl Ord for NsPath
Component-wise order, so a directory sorts before its contents and /a/b sorts before /a-b (a plain string
comparison would put /a-b first because - sorts before /).
impl Ord for NsPath
Component-wise order, so a directory sorts before its contents and /a/b sorts before /a-b (a plain string
comparison would put /a-b first because - sorts before /).
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for NsPath
impl PartialOrd for NsPath
impl StructuralPartialEq for NsPath
Auto Trait Implementations§
impl Forget for NsPath
impl Freeze for NsPath
impl Move for NsPath
impl RefUnwindSafe for NsPath
impl Send for NsPath
impl Sync for NsPath
impl Unpin for NsPath
impl UnsafeUnpin for NsPath
impl UnwindSafe for NsPath
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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
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
key and return true if they are equal.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