Struct fclones::Path

source ·
pub struct Path { /* private fields */ }
Expand description

Memory-efficient file path representation.

When storing multiple paths with common parent, the standard PathBuf would keep the parent path text duplicated in memory, wasting a lot of memory. This structure here shares the common parent between many paths by reference-counted references.

Implementations§

source§

impl Path

source

pub fn canonicalize(&self) -> Path

source

pub fn is_absolute(&self) -> bool

source

pub fn is_relative(&self) -> bool

source

pub fn root(&self) -> Option<&Path>

Returns the absolute root of the path if the path is absolute. In Unix, returns “/”. In Windows this can return a root with prefix e.g. “C:". If path is relative, returns None.

source

pub fn share(self) -> Arc<Self>

Moves this Path under an Arc. You need to wrap Path before joining anything to it.

source

pub fn unshare(self: &Arc<Path>) -> Path

Copies this path from under an Arc. Generally cheap, because only the last component is copied.

source

pub fn join<P: AsRef<Path>>(self: &Arc<Path>, path: P) -> Path

Creates an owned Path with path adjoined to self. The path must be relative.

source

pub fn resolve<P: AsRef<Path>>(self: &Arc<Path>, path: P) -> Path

If path is relative, works the same as join. If path is absolute, ignores self and returns path.

source

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

Returns the name of the last component of this path or None if the path is directory (e.g. root dir or parent dir).

source

pub fn file_name_cstr(&self) -> Option<&CStr>

Returns the name of the last component of this path or None if the path is directory (e.g. root dir or parent dir). Doesn’t allocate anything on the heap.

source

pub fn parent(&self) -> Option<&Arc<Path>>

Returns the parent directory of this path. Doesn’t allocate anything on the heap.

source

pub fn strip_prefix(&self, base: &Path) -> Option<Path>

Returns a path that joined to base would give this path. If base is the same as this path, returns current directory. If this path doesn’t have a base prefix, returns None.

source

pub fn strip_root(&self) -> Path

If this path is absolute, strips the root component and returns a relative path. Otherwise returns a clone of this path. E.g. /foo/bar becomes foo/bar

source

pub fn is_prefix_of(&self, other: &Path) -> bool

Returns true if self is a prefix of another path

source

pub fn to_path_buf(&self) -> PathBuf

Converts this path to a standard library path buffer. We need this to be able to use this path with other standard library I/O functions.

source

pub fn to_string_lossy(&self) -> String

Converts this path to an UTF encoded string. Any non-Unicode sequences are replaced with [U+FFFD REPLACEMENT CHARACTER][U+FFFD].

source

pub fn to_escaped_string(&self) -> String

Returns a lossless string representation in STFU8 format.

source

pub fn from_escaped_string(encoded: &str) -> Result<Path, DecodeError>

Decodes the path from the string encoded with to_escaped_string.

source

pub fn quote(&self) -> String

Formats the path in a way that Posix-shell can decode it. If the path doesn’t contain any special characters, returns it as-is. If the path contains special shell characters like ‘\’ or ‘*’, it is single-quoted. This function also takes care of the characters that cannot be represented in UTF-8 by escaping them with $'\xXX' or $'\uXXXX' syntax.

source

pub fn display(&self) -> String

Returns a representation suitable for display in the console. Control characters like newline or linefeed are escaped.

source

pub fn hash128(&self) -> u128

Returns a hash of the full path. Useful for deduplicating paths without making path clones. We need 128-bits so that collisions are not a problem. Thanks to using a long hash we can be sure collisions won’t be a problem.

source

pub fn component_count(&self) -> usize

Returns the number of components in this path

Trait Implementations§

source§

impl AsRef<Path> for FileInfo

source§

fn as_ref(&self) -> &Path

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

impl AsRef<Path> for Path

source§

fn as_ref(&self) -> &Path

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

impl AsRef<Path> for PathAndMetadata

source§

fn as_ref(&self) -> &Path

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

impl Clone for Path

source§

fn clone(&self) -> Path

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Path

source§

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

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

impl Default for Path

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Path

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<FileInfo> for Path

source§

fn from(info: FileInfo) -> Self

Converts to this type from the input type.
source§

impl<P> From<P> for Path
where P: AsRef<Path>,

source§

fn from(p: P) -> Self

Converts to this type from the input type.
source§

impl From<PathAndMetadata> for Path

source§

fn from(value: PathAndMetadata) -> Self

Converts to this type from the input type.
source§

impl Hash for Path

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 Ord for Path

source§

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

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Path

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Path

source§

fn partial_cmp(&self, other: &Path) -> 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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for Path

source§

fn serialize<S>( &self, serializer: S ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

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

impl ValueParserFactory for Path

Allows to read command line arguments as crate::path::Path.

§

type Parser = PathParser

Generated parser, usually [ValueParser]. Read more
source§

fn value_parser() -> Self::Parser

Create the specified [Self::Parser]
source§

impl Eq for Path

source§

impl StructuralEq for Path

source§

impl StructuralPartialEq for Path

Auto Trait Implementations§

§

impl RefUnwindSafe for Path

§

impl Send for Path

§

impl Sync for Path

§

impl Unpin for Path

§

impl UnwindSafe for Path

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
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

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

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

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

§

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

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

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

§

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

Compare self to key and return true if they are equal.
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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> BincodeSerDeBounds for T

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<T> KV for T