Skip to main content

RedoxReference

Struct RedoxReference 

Source
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>

Source

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.

Source

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

Source

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

Source

pub unsafe fn new_unchecked<S: Into<Cow<'a, str>>>(reference: S) -> Self

SAFETY: Caller ensures that path contains no NUL character

Source

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

Source

pub fn join_checked<'b>(&self, path: RedoxReference<'b>) -> RedoxReference<'b>

Join, but checked from NUL

Source

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.

Source

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.

Source

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

Source

pub fn is_canon(&self) -> bool

Verify that the reference is canonicalized

Source

pub fn dirname<'b>(&self) -> RedoxReference<'b>

Get path upward one time

Source

pub fn dirname_split( &'a self, ) -> (RedoxReference<'a>, Option<RedoxReference<'a>>)

Get path upward one time and the file name

Source

pub fn is_relative(&self) -> bool

Is this path relative?

Source

pub fn into_owned<'b>(self) -> RedoxReference<'b>

Copy the content into owned

Trait Implementations§

Source§

impl<'a> AsRef<str> for RedoxReference<'a>

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a> Clone for RedoxReference<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for RedoxReference<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Display for RedoxReference<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Eq for RedoxReference<'a>

Source§

impl<'a> From<RedoxReference<'a>> for Cow<'a, str>

Source§

fn from(value: RedoxReference<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<RedoxReference<'a>> for RedoxStr<'a>

Source§

fn from(value: RedoxReference<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> Hash for RedoxReference<'a>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> PartialEq for RedoxReference<'a>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'a> StructuralPartialEq for RedoxReference<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for RedoxReference<'a>

§

impl<'a> RefUnwindSafe for RedoxReference<'a>

§

impl<'a> Send for RedoxReference<'a>

§

impl<'a> Sync for RedoxReference<'a>

§

impl<'a> Unpin for RedoxReference<'a>

§

impl<'a> UnsafeUnpin for RedoxReference<'a>

§

impl<'a> UnwindSafe for RedoxReference<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.