pub struct RedoxReference<'a>(/* private fields */);Expand description
The part of a path that is sent to each scheme
Implementations§
Source§impl<'a> RedoxReference<'a>
impl<'a> RedoxReference<'a>
Sourcepub fn new<S: Into<Cow<'a, str>>>(reference: S) -> Option<Self>
pub fn new<S: Into<Cow<'a, str>>>(reference: S) -> Option<Self>
Create a new RedoxReference, ensuring there are no invalid characters.
An empty path is considered valid and equivalent to ‘/’.
A path not starting with ‘/’ will be considered not canonical.
Sourcepub fn new_from_c<S: Into<&'a CStr>>(reference: S) -> Option<Self>
pub fn new_from_c<S: Into<&'a CStr>>(reference: S) -> Option<Self>
Create a new RedoxReference from C string, ensuring it is a valid UTF-8
Sourcepub fn join<'b, S: Into<Cow<'b, str>>>(
&self,
path: S,
) -> Option<RedoxReference<'b>>
pub fn join<'b, S: Into<Cow<'b, str>>>( &self, path: S, ) -> Option<RedoxReference<'b>>
Join a RedoxReference with a path. Relative paths will be joined, absolute paths will
be returned as-is.
Returns Some on success and None if the path is not valid
Sourcepub fn join_checked<'b>(&self, path: RedoxReference<'b>) -> RedoxReference<'b>
pub fn join_checked<'b>(&self, path: RedoxReference<'b>) -> RedoxReference<'b>
Join, but checked from NUL
Sourcepub fn canonical(self) -> Self
pub fn canonical(self) -> Self
Canonicalize RedoxReference, removing ., .. and empty subpaths.
In this function, relative path will be remain relative and the path remain not canon.
Paths that goes upward beyond the root path will be truncated
i.e. /.. converted to / and ../foo/ converted to foo.
Sourcepub fn canonical_max_upward(self, max_upward: usize) -> Option<(Self, usize)>
pub fn canonical_max_upward(self, max_upward: usize) -> Option<(Self, usize)>
Normalize RedoxReference, removing ., .. (if possible) and empty subpaths.
This function will return None if the path is absolute or escapes root.
This function is useful to validate if the path still remain in scope within root.
To make this works within symlink, max_upward is provided, and also returning an integer
for next canonical_max_upward(max_upward). The amount of .. will never exceed max_upward.
Sourcepub fn to_relative(self) -> Self
pub fn to_relative(self) -> Self
Convert RedoxReference into relative path if it’s not already.
Converting the path to relative allows using Self::canonical_max_upward
Sourcepub fn dirname<'b>(&self) -> RedoxReference<'b>
pub fn dirname<'b>(&self) -> RedoxReference<'b>
Get path upward one time
Sourcepub fn is_relative(&self) -> bool
pub fn is_relative(&self) -> bool
Is this path relative?
Sourcepub fn into_owned<'b>(self) -> RedoxReference<'b>
pub fn into_owned<'b>(self) -> RedoxReference<'b>
Copy the content into owned
Trait Implementations§
Source§impl<'a> AsRef<str> for RedoxReference<'a>
impl<'a> AsRef<str> for RedoxReference<'a>
Source§impl<'a> Clone for RedoxReference<'a>
impl<'a> Clone for RedoxReference<'a>
Source§fn clone(&self) -> RedoxReference<'a>
fn clone(&self) -> RedoxReference<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a> Debug for RedoxReference<'a>
impl<'a> Debug for RedoxReference<'a>
Source§impl<'a> Display for RedoxReference<'a>
impl<'a> Display for RedoxReference<'a>
impl<'a> Eq for RedoxReference<'a>
Source§impl<'a> From<RedoxReference<'a>> for Cow<'a, str>
impl<'a> From<RedoxReference<'a>> for Cow<'a, str>
Source§fn from(value: RedoxReference<'a>) -> Self
fn from(value: RedoxReference<'a>) -> Self
Source§impl<'a> From<RedoxReference<'a>> for RedoxStr<'a>
impl<'a> From<RedoxReference<'a>> for RedoxStr<'a>
Source§fn from(value: RedoxReference<'a>) -> Self
fn from(value: RedoxReference<'a>) -> Self
Source§impl<'a> Hash for RedoxReference<'a>
impl<'a> Hash for RedoxReference<'a>
Source§impl<'a> PartialEq for RedoxReference<'a>
impl<'a> PartialEq for RedoxReference<'a>
Source§fn eq(&self, other: &RedoxReference<'a>) -> bool
fn eq(&self, other: &RedoxReference<'a>) -> bool
self and other values to be equal, and is used by ==.