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§
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
Sourcefn components(&self) -> Components<'_> ⓘ
fn components(&self) -> Components<'_> ⓘ
Path components.
Sourcefn parent_result(&self) -> Result<&Self::Path, PathError>
fn parent_result(&self) -> Result<&Self::Path, PathError>
Parent directory.
Sourcefn parents(&self) -> impl Iterator<Item = &Self::Path>
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());Sourcefn paths(&self) -> impl Iterator<Item = &Self::Path>
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());Sourcefn parent_and_file_name(&self) -> Option<(&Self::Path, &str)>
fn parent_and_file_name(&self) -> Option<(&Self::Path, &str)>
Path and filename.
Sourcefn parent_and_file_name_result(&self) -> Result<(&Self::Path, &str), PathError>
fn parent_and_file_name_result(&self) -> Result<(&Self::Path, &str), PathError>
Path and filename.
Sourcefn file_name_result(&self) -> Result<&str, PathError>
fn file_name_result(&self) -> Result<&str, PathError>
File name.
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.