Trait path_abs::PathMut[][src]

pub trait PathMut: PathInfo {
    fn append<P: AsRef<Path>>(&mut self, path: P) -> Result<()>;
fn pop_up(&mut self) -> Result<()>;
fn truncate_to_root(&mut self);
fn set_file_name<S: AsRef<OsStr>>(&mut self, file_name: S);
fn set_extension<S: AsRef<OsStr>>(&mut self, extension: S) -> bool; }

Methods that modify a path.

These methods are not implemented for all path_abs types because they may break the type's invariant. For example, if you could call pop_up() on a PathFile, it would no longer be the path to a file, but the path to a directory.

As a general rule, methods that can return an error will 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).

Required methods

fn append<P: AsRef<Path>>(&mut self, path: P) -> Result<()>[src]

Appends path to this path.

Note that this method represents pure concatenation, not "adjoinment" like PathBuf::push, so absolute paths won't wholly replace the current path.

.. components are resolved using pop_up, which can consume components on self

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 std::path::PathBuf;
use path_abs::PathMut;

let mut somepath = PathBuf::from("foo");
somepath.append("bar");

assert_eq!(somepath, PathBuf::from("foo/bar"));

fn pop_up(&mut self) -> Result<()>[src]

Go "up" one directory.

This removes the last component of this path. It also resolves any .. that exist at the end of the path until a real item can be truncated. If the path is relative, and no items remain then a .. is appended to the path.

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 std::path::Path;
use path_abs::PathMut;

let executable = Path::new("/usr/loca/bin/myapp");
let mut install_path = executable.to_path_buf();
install_path.pop_up()?;

assert_eq!(install_path.as_path(), Path::new("/usr/local/bin"));

Example handling weird relative paths

use std::path::Path;
use path_abs::PathMut;

let executable = Path::new("../../weird/../relative/path/../../");
let mut install_path = executable.to_path_buf();
install_path.pop_up()?;

assert_eq!(install_path.as_path(), Path::new("../../../"));

Error use case

use std::path::Path;
use path_abs::PathMut;

let tmp = Path::new("/tmp");
let mut relative = tmp.to_path_buf();
relative.pop_up()?;
assert!(relative.pop_up().is_err());

fn truncate_to_root(&mut self)[src]

Removes all components after the root, if any.

This is mostly useful on Windows, since it preserves the prefix before the root.

Example

use std::path::PathBuf;
use path_abs::PathMut;

let mut somepath = PathBuf::from(r"C:\foo\bar");
somepath.truncate_to_root();

assert_eq!(somepath, PathBuf::from(r"C:\"));

fn set_file_name<S: AsRef<OsStr>>(&mut self, file_name: S)[src]

fn set_extension<S: AsRef<OsStr>>(&mut self, extension: S) -> bool[src]

Loading content...

Implementations on Foreign Types

impl PathMut for PathBuf[src]

impl PathMut for Arc<PathBuf>[src]

Loading content...

Implementors

impl PathMut for PathSer[src]

impl PathMut for PathAbs[src]

Loading content...