Skip to main content

PathExt

Trait PathExt 

Source
pub trait PathExt {
    type PathOwned: PathExt;
    type Path: PathExt + ?Sized;

Show 21 methods // Required methods fn validate(buf: &str) -> Result<(), PathError>; fn from_owned_unchecked(buf: String) -> Self::PathOwned; fn from_str_unchecked(buf: &str) -> &Self::Path; fn as_str(&self) -> &str; fn has_root(&self) -> bool; // Provided methods fn from_owned(buf: String) -> Result<Self::PathOwned, PathError> { ... } fn from_str(buf: &str) -> Result<&Self::Path, PathError> { ... } fn as_path(&self) -> &Self::Path { ... } fn to_path(&self) -> Self::PathOwned { ... } fn components(&self) -> Components<'_> { ... } fn parent(&self) -> Option<&Self::Path> { ... } fn parent_result(&self) -> Result<&Self::Path, PathError> { ... } fn parents(&self) -> impl Iterator<Item = &Self::Path> { ... } fn paths(&self) -> impl Iterator<Item = &Self::Path> { ... } fn parent_and_file_name(&self) -> Option<(&Self::Path, &str)> { ... } fn parent_and_file_name_result( &self, ) -> Result<(&Self::Path, &str), PathError> { ... } fn file_name(&self) -> Option<&str> { ... } fn file_name_result(&self) -> Result<&str, PathError> { ... } fn normalize(&self) -> Result<Self::PathOwned, PathError> { ... } fn join<'a: 'b, 'b>( &'a self, other: impl IntoIterator<Item = Component<'b>>, ) -> Result<Self::PathOwned, PathError> { ... } fn join_path(&self, other: &str) -> Result<Self::PathOwned, PathError> { ... }
}

Required Associated Types§

Required Methods§

Provided Methods§

Source

fn from_owned(buf: String) -> Result<Self::PathOwned, PathError>

Source

fn from_str(buf: &str) -> Result<&Self::Path, PathError>

Source

fn as_path(&self) -> &Self::Path

Source

fn to_path(&self) -> Self::PathOwned

Source

fn components(&self) -> Components<'_>

Path components.

Source

fn parent(&self) -> Option<&Self::Path>

Parent directory.

Source

fn parent_result(&self) -> Result<&Self::Path, PathError>

Parent directory.

Source

fn parents(&self) -> impl Iterator<Item = &Self::Path>

Parent directories as full path starting at root.

Example:

use co_primitives::{Path, PathExt};
let path = Path::from_str_unchecked("/hello/world/test.zip");
let mut parents = path.parents();
assert_eq!(Some(Path::from_str_unchecked("/")), parents.next());
assert_eq!(Some(Path::from_str_unchecked("/hello")), parents.next());
assert_eq!(Some(Path::from_str_unchecked("/hello/world")), parents.next());
assert_eq!(None, parents.next());
Source

fn paths(&self) -> impl Iterator<Item = &Self::Path>

Components as full path starting at root.

Example:

use co_primitives::{Path, PathExt};
let path = Path::from_str_unchecked("/hello/world/test.zip");
let mut paths = path.paths();
assert_eq!(Some(Path::from_str_unchecked("/")), paths.next());
assert_eq!(Some(Path::from_str_unchecked("/hello")), paths.next());
assert_eq!(Some(Path::from_str_unchecked("/hello/world")), paths.next());
assert_eq!(Some(Path::from_str_unchecked("/hello/world/test.zip")), paths.next());
assert_eq!(None, paths.next());
Source

fn parent_and_file_name(&self) -> Option<(&Self::Path, &str)>

Path and filename.

Source

fn parent_and_file_name_result(&self) -> Result<(&Self::Path, &str), PathError>

Path and filename.

Source

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

File name.

Source

fn file_name_result(&self) -> Result<&str, PathError>

File name.

Source

fn normalize(&self) -> Result<Self::PathOwned, PathError>

Normalize path to connonized form.

Source

fn join<'a: 'b, 'b>( &'a self, other: impl IntoIterator<Item = Component<'b>>, ) -> Result<Self::PathOwned, PathError>

Join and normalize components into an path.

Source

fn join_path(&self, other: &str) -> Result<Self::PathOwned, PathError>

Join and normalize other path.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§