[][src]Trait skellige::prelude::PathExt

pub trait PathExt {
    pub fn abs(&self) -> Result<PathBuf, FuError>;
pub fn abs_from<T>(&self, path: T) -> Result<PathBuf, FuError>
    where
        T: AsRef<Path>
;
pub fn base(&self) -> Result<String, FuError>;
pub fn chmod(&self, mode: u32) -> Result<(), FuError>;
pub fn clean(&self) -> Result<PathBuf, FuError>;
pub fn concat<T>(&self, val: T) -> Result<PathBuf, FuError>
    where
        T: AsRef<str>
;
pub fn dir(&self) -> Result<PathBuf, FuError>;
pub fn empty(&self) -> bool;
pub fn exists(&self) -> bool;
pub fn expand(&self) -> Result<PathBuf, FuError>;
pub fn ext(&self) -> Result<String, FuError>;
pub fn first(&self) -> Result<Component<'_>, FuError>;
pub fn gid(&self) -> Result<u32, FuError>;
pub fn has<T>(&self, path: T) -> bool
    where
        T: AsRef<Path>
;
pub fn has_prefix<T>(&self, prefix: T) -> bool
    where
        T: AsRef<Path>
;
pub fn has_suffix<T>(&self, suffix: T) -> bool
    where
        T: AsRef<Path>
;
pub fn is_dir(&self) -> bool;
pub fn is_exec(&self) -> bool;
pub fn is_file(&self) -> bool;
pub fn is_readonly(&self) -> bool;
pub fn is_symlink(&self) -> bool;
pub fn is_symlink_dir(&self) -> bool;
pub fn is_symlink_file(&self) -> bool;
pub fn last(&self) -> Result<Component<'_>, FuError>;
pub fn mash<T>(&self, path: T) -> PathBuf
    where
        T: AsRef<Path>
;
pub fn metadata(&self) -> Result<Metadata, FuError>;
pub fn mode(&self) -> Result<u32, FuError>;
pub fn name(&self) -> Result<String, FuError>;
pub fn perms(&self) -> Result<Permissions, FuError>;
pub fn readlink(&self) -> Result<PathBuf, FuError>;
pub fn relative_from<T>(&self, path: T) -> Result<PathBuf, FuError>
    where
        T: AsRef<Path>
;
pub fn setperms(&self, perms: Permissions) -> Result<PathBuf, FuError>;
pub fn trim_ext(&self) -> Result<PathBuf, FuError>;
pub fn trim_first(&self) -> PathBuf;
pub fn trim_last(&self) -> PathBuf;
pub fn trim_prefix<T>(&self, prefix: T) -> PathBuf
    where
        T: AsRef<Path>
;
pub fn trim_protocol(&self) -> PathBuf;
pub fn trim_suffix<T>(&self, suffix: T) -> PathBuf
    where
        T: AsRef<Path>
;
pub fn uid(&self) -> Result<u32, FuError>; }

Required methods

pub fn abs(&self) -> Result<PathBuf, FuError>[src]

Return the path in an absolute clean form

Examples

use fungus::prelude::*;

let home = user::home_dir().unwrap();
assert_eq!(PathBuf::from(&home), sys::abs("~").unwrap());

pub fn abs_from<T>(&self, path: T) -> Result<PathBuf, FuError> where
    T: AsRef<Path>, 
[src]

Returns a new absolute PathBuf based on the given absolute Path. The last element of the given path will be assumed to be a file name.

Examples

use fungus::prelude::*;

let home = PathBuf::from("~").abs().unwrap();
assert_eq!(PathBuf::from("foo2").abs_from(home.mash("foo1").abs().unwrap()).unwrap(), home.mash("foo2"));

pub fn base(&self) -> Result<String, FuError>[src]

Returns the final component of the Path, if there is one.

Examples

use fungus::prelude::*;

assert_eq!("bar", PathBuf::from("/foo/bar").base().unwrap());

pub fn chmod(&self, mode: u32) -> Result<(), FuError>[src]

Set the given mode for the Path and return the Path

Examples

use fungus::prelude::*;

let tmpdir = PathBuf::from("tests/temp").abs().unwrap().mash("pathbuf_doc_chmod");
assert!(sys::remove_all(&tmpdir).is_ok());
let file1 = tmpdir.mash("file1");
assert!(sys::mkdir(&tmpdir).is_ok());
assert!(sys::touch(&file1).is_ok());
assert!(file1.chmod(0o644).is_ok());
assert_eq!(file1.mode().unwrap(), 0o100644);
assert!(file1.chmod(0o555).is_ok());
assert_eq!(file1.mode().unwrap(), 0o100555);
assert!(sys::remove_all(&tmpdir).is_ok());

pub fn clean(&self) -> Result<PathBuf, FuError>[src]

Return the shortest path equivalent to the path by purely lexical processing and thus does not handle links correctly in some cases, use canonicalize in those cases. It applies the following rules interatively until no further processing can be done.

  1. Replace multiple slashes with a single
  2. Eliminate each . path name element (the current directory)
  3. Eliminate each inner .. path name element (the parent directory) along with the non-.. element that precedes it.
  4. Eliminate .. elements that begin a rooted path: that is, replace "/.." by "/" at the beginning of a path.
  5. Leave intact ".." elements that begin a non-rooted path.
  6. Drop trailing '/' unless it is the root

If the result of this process is an empty string, return the string ., representing the current directory.

pub fn concat<T>(&self, val: T) -> Result<PathBuf, FuError> where
    T: AsRef<str>, 
[src]

Returns the Path with the given string concatenated on.

Examples

use fungus::prelude::*;

assert_eq!(Path::new("/foo/bar").concat(".rs").unwrap(), PathBuf::from("/foo/bar.rs"));

pub fn dir(&self) -> Result<PathBuf, FuError>[src]

Returns the Path without its final component, if there is one.

Examples

use fungus::prelude::*;

let dir = PathBuf::from("/foo/bar").dir().unwrap();
assert_eq!(PathBuf::from("/foo").as_path(), dir);

pub fn empty(&self) -> bool[src]

Returns true if the Path is empty.

Examples

use fungus::prelude::*;

assert_eq!(PathBuf::from("").empty(), true);

pub fn exists(&self) -> bool[src]

Returns true if the Path exists. Handles path expansion.

Examples

use fungus::prelude::*;

assert_eq!(Path::new("/etc").exists(), true);

pub fn expand(&self) -> Result<PathBuf, FuError>[src]

Expand the path to include the home prefix if necessary

Examples

use fungus::prelude::*;

let home = user::home_dir().unwrap();
assert_eq!(PathBuf::from(&home).mash("foo"), PathBuf::from("~/foo").expand().unwrap());

pub fn ext(&self) -> Result<String, FuError>[src]

Returns the extension of the path or an error.

Examples

use fungus::prelude::*;

assert_eq!(Path::new("foo.bar").ext().unwrap(), "bar");

pub fn first(&self) -> Result<Component<'_>, FuError>[src]

Returns the first path component.

Examples

use fungus::prelude::*;
use std::path::Component;

let first = Component::Normal(OsStr::new("foo"));
assert_eq!(PathBuf::from("foo/bar").first().unwrap(), first);

pub fn gid(&self) -> Result<u32, FuError>[src]

Returns the group ID of the owner of this file.

Examples

use fungus::prelude::*;

assert_eq!(Path::new("/etc").gid().unwrap(), 0);

pub fn has<T>(&self, path: T) -> bool where
    T: AsRef<Path>, 
[src]

Returns true if the Path contains the given path or string.

Examples

use fungus::prelude::*;

let path = PathBuf::from("/foo/bar");
assert_eq!(path.has("foo"), true);
assert_eq!(path.has("/foo"), true);

pub fn has_prefix<T>(&self, prefix: T) -> bool where
    T: AsRef<Path>, 
[src]

Returns true if the Path as a String has the given prefix

Examples

use fungus::prelude::*;

let path = PathBuf::from("/foo/bar");
assert_eq!(path.has_prefix("/foo"), true);
assert_eq!(path.has_prefix("foo"), false);

pub fn has_suffix<T>(&self, suffix: T) -> bool where
    T: AsRef<Path>, 
[src]

Returns true if the Path as a String has the given suffix

Examples

use fungus::prelude::*;

let path = PathBuf::from("/foo/bar");
assert_eq!(path.has_suffix("/bar"), true);
assert_eq!(path.has_suffix("foo"), false);

pub fn is_dir(&self) -> bool[src]

Returns true if the Path exists and is a directory. Handles path expansion.

Examples

use fungus::prelude::*;

assert_eq!(Path::new("/etc").is_dir(), true);

pub fn is_exec(&self) -> bool[src]

Returns true if the Path exists and is an executable. Handles path expansion.

Examples

use fungus::prelude::*;

let tmpdir = PathBuf::from("tests/temp").abs().unwrap().mash("doc_is_exec");
assert!(sys::remove_all(&tmpdir).is_ok());
assert!(sys::mkdir(&tmpdir).is_ok());
let file1 = tmpdir.mash("file1");
assert!(sys::touch_p(&file1, 0o644).is_ok());
assert_eq!(file1.is_exec(), false);
assert!(sys::chmod_p(&file1).unwrap().add_x().chmod().is_ok());
assert_eq!(file1.mode().unwrap(), 0o100755);
assert_eq!(file1.is_exec(), true);
assert!(sys::remove_all(&tmpdir).is_ok());

pub fn is_file(&self) -> bool[src]

Returns true if the Path exists and is a file. Handles path expansion

Examples

use fungus::prelude::*;

assert_eq!(Path::new("/etc/hosts").is_file(), true);

pub fn is_readonly(&self) -> bool[src]

Returns true if the Path exists and is readonly. Handles path expansion.

Examples

use fungus::prelude::*;

let tmpdir = PathBuf::from("tests/temp").abs().unwrap().mash("doc_is_readonly");
assert!(sys::remove_all(&tmpdir).is_ok());
assert!(sys::mkdir(&tmpdir).is_ok());
let file1 = tmpdir.mash("file1");
assert!(sys::touch_p(&file1, 0o644).is_ok());
assert_eq!(file1.is_readonly(), false);
assert!(sys::chmod_p(&file1).unwrap().readonly().chmod().is_ok());
assert_eq!(file1.mode().unwrap(), 0o100444);
assert_eq!(file1.is_readonly(), true);
assert!(sys::remove_all(&tmpdir).is_ok());

Returns true if the Path exists and is a symlink. Handles path expansion

Examples

use fungus::prelude::*;

let tmpdir = PathBuf::from("tests/temp").abs().unwrap().mash("pathbuf_doc_is_symlink");
assert!(sys::remove_all(&tmpdir).is_ok());
let file1 = tmpdir.mash("file1");
let link1 = tmpdir.mash("link1");
assert!(sys::mkdir(&tmpdir).is_ok());
assert!(sys::touch(&file1).is_ok());
assert!(sys::symlink(&link1, &file1).is_ok());
assert_eq!(link1.is_symlink(), true);
assert!(sys::remove_all(&tmpdir).is_ok());

Returns true if the Path exists and is a symlinked directory. Handles path expansion

Examples

use fungus::prelude::*;

let tmpdir = PathBuf::from("tests/temp").abs().unwrap().mash("pathbuf_doc_is_symlink_dir");
assert!(sys::remove_all(&tmpdir).is_ok());
let dir1 = tmpdir.mash("dir1");
let link1 = tmpdir.mash("link1");
assert!(sys::mkdir(&dir1).is_ok());
assert!(sys::symlink(&link1, &dir1).is_ok());
assert_eq!(link1.is_symlink_dir(), true);
assert!(sys::remove_all(&tmpdir).is_ok());

Returns true if the given Path exists and is a symlinked file. Handles path expansion

Examples

use fungus::prelude::*;

let tmpdir = PathBuf::from("tests/temp").abs().unwrap().mash("pathbuf_doc_is_symlink_file");
assert!(sys::remove_all(&tmpdir).is_ok());
let file1 = tmpdir.mash("file1");
let link1 = tmpdir.mash("link1");
assert!(sys::mkdir(&tmpdir).is_ok());
assert!(sys::touch(&file1).is_ok());
assert!(sys::symlink(&link1, &file1).is_ok());
assert_eq!(link1.is_symlink_file(), true);
assert!(sys::remove_all(&tmpdir).is_ok());

pub fn last(&self) -> Result<Component<'_>, FuError>[src]

Returns the last path component.

Examples

use fungus::prelude::*;
use std::path::Component;

let first = Component::Normal(OsStr::new("bar"));
assert_eq!(PathBuf::from("foo/bar").last().unwrap(), first);

pub fn mash<T>(&self, path: T) -> PathBuf where
    T: AsRef<Path>, 
[src]

Returns a new owned PathBuf from self mashed together with path. Differs from the mash implementation as mash drops root prefix of the given path if it exists and also drops any trailing '/' on the new resulting path. More closely aligns with the Golang implementation of join.

Examples

use fungus::prelude::*;

assert_eq!(Path::new("/foo").mash("/bar"), PathBuf::from("/foo/bar"));

pub fn metadata(&self) -> Result<Metadata, FuError>[src]

Returns the Metadata object for the Path if it exists else and error

Examples

use fungus::prelude::*;

let meta = Path::new("/etc").metadata().unwrap();
assert_eq!(meta.is_dir(), true);

pub fn mode(&self) -> Result<u32, FuError>[src]

Returns the Metadata object for the Path if it exists else and error

Examples

use fungus::prelude::*;

let tmpdir = PathBuf::from("tests/temp").abs().unwrap().mash("pathbuf_doc_mode");
assert!(sys::remove_all(&tmpdir).is_ok());
let file1 = tmpdir.mash("file1");
assert!(sys::mkdir(&tmpdir).is_ok());
assert!(sys::touch(&file1).is_ok());
assert!(file1.chmod(0o644).is_ok());
assert_eq!(file1.mode().unwrap(), 0o100644);
assert!(sys::remove_all(&tmpdir).is_ok());

pub fn name(&self) -> Result<String, FuError>[src]

Returns the final component of the Path without an extension if there is one

Examples

use fungus::prelude::*;

assert_eq!(PathBuf::from("/foo/bar.foo").name().unwrap(), "bar");

pub fn perms(&self) -> Result<Permissions, FuError>[src]

Return the permissions for the Path

Examples

use fungus::prelude::*;

let tmpdir = PathBuf::from("tests/temp").abs().unwrap().mash("pathbuf_doc_perms");
assert!(sys::remove_all(&tmpdir).is_ok());
let file1 = tmpdir.mash("file1");
assert!(sys::mkdir(&tmpdir).is_ok());
assert!(sys::touch(&file1).is_ok());
assert!(file1.chmod(0o644).is_ok());
assert_eq!(file1.perms().unwrap().mode(), 0o100644);
assert!(sys::remove_all(&tmpdir).is_ok());

Returns the absolute path for the link target. Handles path expansion

Examples

use fungus::prelude::*;

let tmpdir = PathBuf::from("tests/temp").abs().unwrap().mash("pathbuf_doc_readlink");
assert!(sys::remove_all(&tmpdir).is_ok());
let file1 = tmpdir.mash("file1");
let link1 = tmpdir.mash("link1");
assert!(sys::mkdir(&tmpdir).is_ok());
assert!(sys::touch(&file1).is_ok());
assert!(sys::symlink(&link1, &file1).is_ok());
assert_eq!(link1.readlink().unwrap(), file1);
assert!(sys::remove_all(&tmpdir).is_ok());

pub fn relative_from<T>(&self, path: T) -> Result<PathBuf, FuError> where
    T: AsRef<Path>, 
[src]

Returns the Path relative to the given Path

Examples

use fungus::prelude::*;

assert_eq!(PathBuf::from("foo/bar1").relative_from("foo/bar2").unwrap(), PathBuf::from("bar1"));

pub fn setperms(&self, perms: Permissions) -> Result<PathBuf, FuError>[src]

Set the given [Permissions] on the Path and return the Path

Examples

use fungus::prelude::*;

let tmpdir = PathBuf::from("tests/temp").abs().unwrap().mash("pathbuf_doc_setperms");
assert!(sys::remove_all(&tmpdir).is_ok());
let file1 = tmpdir.mash("file1");
assert!(sys::mkdir(&tmpdir).is_ok());
assert!(sys::touch(&file1).is_ok());
assert!(file1.chmod(0o644).is_ok());
assert_eq!(file1.perms().unwrap().mode(), 0o100644);
assert!(file1.setperms(fs::Permissions::from_mode(0o555)).is_ok());
assert_eq!(file1.perms().unwrap().mode(), 0o100555);
assert!(sys::remove_all(&tmpdir).is_ok());

pub fn trim_ext(&self) -> Result<PathBuf, FuError>[src]

Returns a new PathBuf with the file extension trimmed off.

Examples

use fungus::prelude::*;

assert_eq!(Path::new("foo.exe").trim_ext().unwrap(), PathBuf::from("foo"));

pub fn trim_first(&self) -> PathBuf[src]

Returns a new PathBuf with first Component trimmed off.

Examples

use fungus::prelude::*;

assert_eq!(PathBuf::from("/foo").trim_first(), PathBuf::from("foo"));

pub fn trim_last(&self) -> PathBuf[src]

Returns a new PathBuf with last Component trimmed off.

Examples

use fungus::prelude::*;

assert_eq!(PathBuf::from("/foo").trim_last(), PathBuf::from("/"));

pub fn trim_prefix<T>(&self, prefix: T) -> PathBuf where
    T: AsRef<Path>, 
[src]

Returns a new PathBuf with the given prefix trimmed off else the original path.

Examples

use fungus::prelude::*;

assert_eq!(Path::new("/foo/bar").trim_prefix("/foo"), PathBuf::from("/bar"));

pub fn trim_protocol(&self) -> PathBuf[src]

Returns a new PathBuf with well known protocol prefixes trimmed off else the original path.

Examples

use fungus::prelude::*;

assert_eq!(PathBuf::from("ftp://foo").trim_protocol(), PathBuf::from("foo"));

pub fn trim_suffix<T>(&self, suffix: T) -> PathBuf where
    T: AsRef<Path>, 
[src]

Returns a new PathBuf with the given suffix trimmed off else the original path.

Examples

use fungus::prelude::*;

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

pub fn uid(&self) -> Result<u32, FuError>[src]

Returns the user ID of the owner of this file.

Examples

use fungus::prelude::*;

assert_eq!(Path::new("/etc").uid().unwrap(), 0);
Loading content...

Implementors

impl PathExt for Path[src]

Loading content...