RelPath

Struct RelPath 

Source
pub struct RelPath(/* private fields */);
Expand description

A file system path that is guaranteed to be relative and normalized.

This type can be used to represent paths in a uniform way, regardless of whether they refer to Windows or POSIX file systems, and regardless of the host platform.

Internally, paths are stored in POSIX (‘/’-delimited) format, but they can be displayed in either POSIX or Windows format.

Relative paths are also guaranteed to be valid unicode.

Implementations§

Source§

impl RelPath

Source

pub fn empty() -> &'static Self

Creates an empty RelPath.

Source

pub fn new<'a>(path: &'a Path, path_style: PathStyle) -> Result<Cow<'a, Self>>

Converts a path with a given style into a RelPath.

Returns an error if the path is absolute, or is not valid unicode.

This method will normalize the path by removing . components, processing .. components, and removing trailing separators. It does not allocate unless it’s necessary to reformat the path.

Source

pub fn unix<S: AsRef<Path> + ?Sized>(path: &S) -> Result<&Self>

Converts a path that is already normalized and uses ‘/’ separators into a RelPath .

Returns an error if the path is not already in the correct format.

Source

pub fn is_empty(&self) -> bool

Source

pub fn components(&self) -> RelPathComponents<'_>

Source

pub fn ancestors(&self) -> RelPathAncestors<'_>

Source

pub fn file_name(&self) -> Option<&str>

Source

pub fn file_stem(&self) -> Option<&str>

Source

pub fn extension(&self) -> Option<&str>

Source

pub fn parent(&self) -> Option<&Self>

Source

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

Source

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

Source

pub fn strip_prefix<'a>(&'a self, other: &Self) -> Result<&'a Self>

Source

pub fn len(&self) -> usize

Source

pub fn last_n_components(&self, count: usize) -> Option<&Self>

Source

pub fn join(&self, other: &Self) -> Arc<Self>

Source

pub fn to_rel_path_buf(&self) -> RelPathBuf

Source

pub fn into_arc(&self) -> Arc<Self>

Source

pub fn to_proto(&self) -> String

Convert the path into the wire representation.

Source

pub fn from_proto(path: &str) -> Result<Arc<Self>>

Load the path from its wire representation.

Source

pub fn display(&self, style: PathStyle) -> Cow<'_, str>

Convert the path into a string with the given path style.

Whenever a path is presented to the user, it should be converted to a string via this method.

Source

pub fn as_unix_str(&self) -> &str

Get the internal unix-style representation of the path.

This should not be shown to the user.

Source

pub fn as_std_path(&self) -> &Path

Interprets the path as a std::path::Path, suitable for file system calls.

This is guaranteed to be a valid path regardless of the host platform, because the / is accepted as a path separator on windows.

This should not be shown to the user.

Trait Implementations§

Source§

impl AsRef<RelPath> for RelPathBuf

Source§

fn as_ref(&self) -> &RelPath

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

impl Borrow<RelPath> for RelPathBuf

Source§

fn borrow(&self) -> &RelPath

Immutably borrows from an owned value. Read more
Source§

impl Debug for RelPath

Source§

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

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

impl From<&RelPath> for Arc<RelPath>

Source§

fn from(rel_path: &RelPath) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a RelPath> for Cow<'a, RelPath>

Source§

fn from(value: &'a RelPath) -> Self

Converts to this type from the input type.
Source§

impl Hash for RelPath

Source§

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

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

impl Ord for RelPath

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
Source§

impl PartialEq<str> for RelPath

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for RelPath

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for RelPath

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for RelPath

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl ToOwned for RelPath

Source§

type Owned = RelPathBuf

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> Self::Owned

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

fn clone_into(&self, target: &mut Self::Owned)

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

impl Eq for RelPath

Source§

impl StructuralPartialEq for RelPath

Auto Trait Implementations§

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<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>