[][src]Struct path_dsl::PathDSL

pub struct PathDSL { /* fields omitted */ }

A PathBuf wrapper that has support for a Path DSL.

It is usable nearly identically to a PathBuf. Supports Deref to PathBuf to cover all edge cases.

See crate documentation for usage examples.

Methods

impl PathDSL[src]

pub fn new() -> Self[src]

pub fn into_os_string(self) -> OsString[src]

pub fn into_boxed_path(self) -> Box<Path>[src]

Methods from Deref<Target = PathBuf>

pub fn as_path(&self) -> &Path1.0.0[src]

Coerces to a Path slice.

Examples

use std::path::{Path, PathBuf};

let p = PathBuf::from("/test");
assert_eq!(Path::new("/test"), p.as_path());

pub fn push<P>(&mut self, path: P) where
    P: AsRef<Path>, 
1.0.0[src]

Extends self with path.

If path is absolute, it replaces the current path.

On Windows:

  • if path has a root but no prefix (e.g., \windows), it replaces everything except for the prefix (if any) of self.
  • if path has a prefix but no root, it replaces self.

Examples

Pushing a relative path extends the existing path:

use std::path::PathBuf;

let mut path = PathBuf::from("/tmp");
path.push("file.bk");
assert_eq!(path, PathBuf::from("/tmp/file.bk"));

Pushing an absolute path replaces the existing path:

use std::path::PathBuf;

let mut path = PathBuf::from("/tmp");
path.push("/etc");
assert_eq!(path, PathBuf::from("/etc"));

pub fn pop(&mut self) -> bool1.0.0[src]

Truncates self to self.parent.

Returns false and does nothing if self.parent is None. Otherwise, returns true.

Examples

use std::path::{Path, PathBuf};

let mut p = PathBuf::from("/test/test.rs");

p.pop();
assert_eq!(Path::new("/test"), p);
p.pop();
assert_eq!(Path::new("/"), p);

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

Updates self.file_name to file_name.

If self.file_name was None, this is equivalent to pushing file_name.

Otherwise it is equivalent to calling pop and then pushing file_name. The new path will be a sibling of the original path. (That is, it will have the same parent.)

Examples

use std::path::PathBuf;

let mut buf = PathBuf::from("/");
assert!(buf.file_name() == None);
buf.set_file_name("bar");
assert!(buf == PathBuf::from("/bar"));
assert!(buf.file_name().is_some());
buf.set_file_name("baz.txt");
assert!(buf == PathBuf::from("/baz.txt"));

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

Updates self.extension to extension.

Returns false and does nothing if self.file_name is None, returns true and updates the extension otherwise.

If self.extension is None, the extension is added; otherwise it is replaced.

Examples

use std::path::{Path, PathBuf};

let mut p = PathBuf::from("/feel/the");

p.set_extension("force");
assert_eq!(Path::new("/feel/the.force"), p.as_path());

p.set_extension("dark_side");
assert_eq!(Path::new("/feel/the.dark_side"), p.as_path());

pub fn capacity(&self) -> usize[src]

🔬 This is a nightly-only experimental API. (path_buf_capacity)

Invokes capacity on the underlying instance of OsString.

pub fn clear(&mut self)[src]

🔬 This is a nightly-only experimental API. (path_buf_capacity)

Invokes clear on the underlying instance of OsString.

pub fn reserve(&mut self, additional: usize)[src]

🔬 This is a nightly-only experimental API. (path_buf_capacity)

Invokes reserve on the underlying instance of OsString.

pub fn reserve_exact(&mut self, additional: usize)[src]

🔬 This is a nightly-only experimental API. (path_buf_capacity)

Invokes reserve_exact on the underlying instance of OsString.

pub fn shrink_to_fit(&mut self)[src]

🔬 This is a nightly-only experimental API. (path_buf_capacity)

Invokes shrink_to_fit on the underlying instance of OsString.

pub fn shrink_to(&mut self, min_capacity: usize)[src]

🔬 This is a nightly-only experimental API. (path_buf_capacity)

Invokes shrink_to on the underlying instance of OsString.

Trait Implementations

impl Clone for PathDSL[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl AsRef<Path> for PathDSL[src]

impl Default for PathDSL[src]

impl<'_, T: ?Sized> From<&'_ T> for PathDSL where
    T: AsRef<Path>, 
[src]

impl From<PathBuf> for PathDSL[src]

impl From<OsString> for PathDSL[src]

impl From<String> for PathDSL[src]

impl From<Box<Path>> for PathDSL[src]

impl<'_> From<Cow<'_, Path>> for PathDSL[src]

impl Into<OsString> for PathDSL[src]

impl Into<Box<Path>> for PathDSL[src]

impl<'a> Into<Cow<'a, Path>> for PathDSL[src]

impl<'a> Into<Cow<'a, Path>> for &'a PathDSL[src]

impl<'a> Into<Arc<Path>> for PathDSL[src]

impl<'a> Into<Rc<Path>> for PathDSL[src]

impl AsMut<PathBuf> for PathDSL[src]

impl DerefMut for PathDSL[src]

impl Debug for PathDSL[src]

impl Div<PathDSL> for PathDSL[src]

type Output = PathDSL

The resulting type after applying the / operator.

impl<'_, T: ?Sized> Div<&'_ T> for PathDSL where
    T: AsRef<Path>, 
[src]

type Output = PathDSL

The resulting type after applying the / operator.

impl Div<OsString> for PathDSL[src]

type Output = PathDSL

The resulting type after applying the / operator.

impl Div<String> for PathDSL[src]

type Output = PathDSL

The resulting type after applying the / operator.

impl Div<PathBuf> for PathDSL[src]

type Output = PathDSL

The resulting type after applying the / operator.

impl Div<Box<Path>> for PathDSL[src]

type Output = PathDSL

The resulting type after applying the / operator.

impl<'_> Div<Cow<'_, Path>> for PathDSL[src]

type Output = PathDSL

The resulting type after applying the / operator.

impl<'_> Div<PathDSL> for &'_ PathDSL[src]

type Output = PathDSL

The resulting type after applying the / operator.

impl<'_, '_, T: ?Sized> Div<&'_ T> for &'_ PathDSL where
    T: AsRef<Path>, 
[src]

type Output = PathDSL

The resulting type after applying the / operator.

impl<'_> Div<OsString> for &'_ PathDSL[src]

type Output = PathDSL

The resulting type after applying the / operator.

impl<'_> Div<String> for &'_ PathDSL[src]

type Output = PathDSL

The resulting type after applying the / operator.

impl<'_> Div<PathBuf> for &'_ PathDSL[src]

type Output = PathDSL

The resulting type after applying the / operator.

impl<'_> Div<Box<Path>> for &'_ PathDSL[src]

type Output = PathDSL

The resulting type after applying the / operator.

impl<'_, '_> Div<Cow<'_, Path>> for &'_ PathDSL[src]

type Output = PathDSL

The resulting type after applying the / operator.

impl Deref for PathDSL[src]

type Target = PathBuf

The resulting type after dereferencing.

Auto Trait Implementations

impl Sync for PathDSL

impl Send for PathDSL

impl Unpin for PathDSL

impl RefUnwindSafe for PathDSL

impl UnwindSafe for PathDSL

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]