Struct VirtualPath

Source
pub struct VirtualPath { /* private fields */ }
Expand description

A wrapper type that allows doing path operations on strings, without considerations for any concrete file system. These paths are supposed to be absolute and should start with a ‘/’.

Implementations§

Source§

impl VirtualPath

Source

pub const fn root() -> &'static Self

Return the root path: “/”

Source

pub fn is_root(&self) -> bool

Check if this path represent a “root”

Source

pub fn len(&self) -> usize

Return the number of elements in the path

Source

pub fn is_empty(&self) -> bool

alias for Self::is_root

Source

pub fn chroot(&self, new_root: &VirtualPath) -> Result<&Self, VirtualPathError>

Return a new VirtualPath with a new root

Source

pub fn is_inside(&self, other: &VirtualPath) -> bool

Return true if the node pointed by “self” is contained in “other”, eventually recursively Return also true if self == other

Source

pub fn name(&self) -> &str

Return the name of the element pointed by this path

Source

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

Return the parent of this path, if any

Source

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

Return the top level directory of this path, for example “a” in “/a/b/c”. Return None is the provided path is the root

Source

pub fn top_level_split(&self) -> Option<(&str, &Self)>

Return the path split in two components, the top level and the rest. For example, the path “a/b/c” will return Some(“a”, “/b/c”). Return None when called on a root path.

Source

pub fn iter(&self) -> VirtualPathIterator<'_>

Return an iterator over the components of the path

Trait Implementations§

Source§

impl AsRef<Path> for VirtualPath

Source§

fn as_ref(&self) -> &Path

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

impl AsRef<VirtualPath> for VirtualPathBuf

Source§

fn as_ref(&self) -> &VirtualPath

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

impl Borrow<VirtualPath> for VirtualPathBuf

Source§

fn borrow(&self) -> &VirtualPath

Immutably borrows from an owned value. Read more
Source§

impl Debug for VirtualPath

Source§

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

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

impl<'a> From<&'a VirtualPath> for &'a str

Source§

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

Converts to this type from the input type.
Source§

impl Ord for VirtualPath

Source§

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

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

impl<'a> PartialEq<&'a VirtualPath> for VirtualPathBuf

Source§

fn eq(&self, other: &&'a VirtualPath) -> 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<VirtualPathBuf> for &VirtualPath

Source§

fn eq(&self, other: &VirtualPathBuf) -> 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 VirtualPath

Source§

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

Source§

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

Source§

type Owned = VirtualPathBuf

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<'a> TryFrom<&'a str> for &'a VirtualPath

Source§

type Error = VirtualPathError

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

fn try_from(value: &'a str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for VirtualPath

Source§

impl StructuralPartialEq for VirtualPath

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more