Trait path_abs::PathOps[][src]

pub trait PathOps: PathInfo {
    type Output: PathOps;
    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; }

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.

Associated Types

Loading content...

Required methods

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

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
}

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

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

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

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.

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

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.

Loading content...

Implementations on Foreign Types

impl PathOps for Path[src]

type Output = PathBuf

impl PathOps for PathBuf[src]

type Output = PathBuf

impl PathOps for Arc<PathBuf>[src]

type Output = Arc<PathBuf>

Loading content...

Implementors

impl PathOps for PathType[src]

type Output = PathAbs

impl PathOps for PathSer[src]

type Output = PathSer

impl PathOps for PathAbs[src]

type Output = PathAbs

impl PathOps for PathDir[src]

type Output = PathAbs

impl PathOps for PathFile[src]

type Output = PathAbs

Loading content...