[][src]Struct mail_template::CwdBaseDir

pub struct CwdBaseDir(_);

Methods

impl CwdBaseDir[src]

pub fn new_unchanged(path: PathBuf) -> Self[src]

Creates a new CwdBaseDir instance containing exactly the given path.

pub fn from_path<P>(path: P) -> Result<Self, Error> where
    P: AsRef<Path> + Into<PathBuf>, 
[src]

Creates a CwdBaseDir from a path by prefixing the path with the current working dir if it's relative.

If the path is not relative it's directly used.

Os state side effects

As this function accesses the current working directory (CWD) it's not pure as the CWD can be changed (e.g. by std::env::set_current_dir).

Error

As getting the CWD can fail this function can fail with a I/O Error, too.

pub fn to_base_path(&self) -> Result<&Path, Error>[src]

Turns this path into a PathBuf by stripping the current working dir if it starts with it.

If this path does not start with the CWD it's returned directly.

Os state side effects

As this function used the current working dir (CWD) it is affected by any function changing the CWD as a side effect.

Error

Accessing the current working dir can fail, as such this function can fail.

pub fn into_inner_with_prefix(self) -> PathBuf[src]

Turns this instance into the PathBuf it dereferences to.

Methods from Deref<Target = PathBuf>

pub fn as_path(&self) -> &Path
1.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) -> bool
1.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 PartialOrd<CwdBaseDir> for CwdBaseDir[src]

impl AsRef<Path> for CwdBaseDir[src]

impl PartialEq<CwdBaseDir> for CwdBaseDir[src]

impl Clone for CwdBaseDir[src]

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

Performs copy-assignment from source. Read more

impl Ord for CwdBaseDir[src]

fn max(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the minimum of two values. Read more

fn clamp(self, min: Self, max: Self) -> Self[src]

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

Returns max if self is greater than max, and min if self is less than min. Otherwise this will return self. Panics if min > max. Read more

impl Eq for CwdBaseDir[src]

impl Debug for CwdBaseDir[src]

impl Deref for CwdBaseDir[src]

type Target = PathBuf

The resulting type after dereferencing.

impl DerefMut for CwdBaseDir[src]

impl Hash for CwdBaseDir[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl Serialize for CwdBaseDir[src]

impl<'de> Deserialize<'de> for CwdBaseDir[src]

Auto Trait Implementations

impl Send for CwdBaseDir

impl Sync for CwdBaseDir

Blanket Implementations

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

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

type Owned = T

impl<T> From for T[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

impl<T, U> TryInto 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> Any for T where
    T: 'static + ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<T> HeaderTryFrom for T[src]

impl<F, T> HeaderTryInto for F where
    T: HeaderTryFrom<F>, 
[src]

impl<T> Erased for T