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 new_from_buf(path: &'a [u8], len: usize) -> Option<Self>
pub fn new_from_buf(path: &'a [u8], len: usize) -> Option<Self>
Create a RedoxReference from a buf, returns None if it not a valid UTF-8 or valid from NUL
Sourcepub unsafe fn new_unchecked<S: Into<Cow<'a, str>>>(reference: S) -> Self
pub unsafe fn new_unchecked<S: Into<Cow<'a, str>>>(reference: S) -> Self
SAFETY: Caller ensures that path contains no NUL character
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 dirname_split(
&'a self,
) -> (RedoxReference<'a>, Option<RedoxReference<'a>>)
pub fn dirname_split( &'a self, ) -> (RedoxReference<'a>, Option<RedoxReference<'a>>)
Get path upward one time and the file name
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