Trait path_abs::PathOps

source ·
pub trait PathOps: PathInfo {
    type Output: PathOps;

    // Required methods
    fn concat<P: AsRef<Path>>(&self, path: P) -> Result<Self::Output>;
    fn join<P: AsRef<Path>>(&self, path: P) -> Self::Output;
    fn with_file_name<S: AsRef<OsStr>>(&self, file_name: S) -> Self::Output;
    fn with_extension<S: AsRef<OsStr>>(&self, extension: S) -> Self::Output;
}
Expand description

Methods that return new path-like objects.

Like the methods of PathInfo and PathMut, these methods are similar to ones from the standard library’s PathBuf but may return a rich path_abs::Error instead of a std::io::Error (although it will automatically convert into a std::io::Error with ? if needed).

Unlike the methods of PathInfo and PathMut, different types that implement this trait may have different return types.

Required Associated Types§

Required Methods§

source

fn concat<P: AsRef<Path>>(&self, path: P) -> Result<Self::Output>

Returns a new value representing the concatenation of two paths.

Note that this method represents pure concatenation, not “adjoinment” like PathBuf::join, so absolute paths won’t wholly replace the current path. See append for more information about how it works.

Errors

This method returns an error if the result would try to go outside a filesystem root, like / on Unix or C:\ on Windows.

Example
use path_abs::{PathInfo, PathOps, Result};

fn find_config_file<P: PathOps>(
    search_path: &[P],
    file_name: &str,
) -> Option<<P as PathOps>::Output> {
    for each in search_path.iter() {
        if let Ok(maybe_config) = each.concat(file_name) {
            if maybe_config.is_file() { return Some(maybe_config); }
        }
    }

    None
}
source

fn join<P: AsRef<Path>>(&self, path: P) -> Self::Output

An exact replica of std::path::Path::join with all of its gotchas and pitfalls,, except returns a more relevant type.

In general, prefer concat

source

fn with_file_name<S: AsRef<OsStr>>(&self, file_name: S) -> Self::Output

Creates a new path object like self but with the given file name.

The same as std::path::Path::with_file_name(), except that the return type depends on the trait implementation.

source

fn with_extension<S: AsRef<OsStr>>(&self, extension: S) -> Self::Output

Creates a new path object like self but with the given extension.

The same as std::path::Path::with_extension(), except that the return type depends on the trait implementation.

Implementations on Foreign Types§

source§

impl PathOps for Arc<PathBuf>

§

type Output = Arc<PathBuf>

source§

fn concat<P: AsRef<Path>>(&self, path: P) -> Result<Self::Output>

source§

fn join<P: AsRef<Path>>(&self, path: P) -> Self::Output

source§

fn with_file_name<S: AsRef<OsStr>>(&self, file_name: S) -> Self::Output

source§

fn with_extension<S: AsRef<OsStr>>(&self, extension: S) -> Self::Output

source§

impl PathOps for PathBuf

§

type Output = PathBuf

source§

fn concat<P: AsRef<Path>>(&self, path: P) -> Result<Self::Output>

source§

fn join<P: AsRef<Path>>(&self, path: P) -> Self::Output

source§

fn with_file_name<S: AsRef<OsStr>>(&self, file_name: S) -> Self::Output

source§

fn with_extension<S: AsRef<OsStr>>(&self, extension: S) -> Self::Output

source§

impl PathOps for Path

§

type Output = PathBuf

source§

fn concat<P: AsRef<Path>>(&self, path: P) -> Result<Self::Output>

source§

fn join<P: AsRef<Path>>(&self, path: P) -> Self::Output

source§

fn with_file_name<S: AsRef<OsStr>>(&self, file_name: S) -> Self::Output

source§

fn with_extension<S: AsRef<OsStr>>(&self, extension: S) -> Self::Output

Implementors§