[][src]Struct mktemp::Temp

pub struct Temp { /* fields omitted */ }

Methods

impl Temp[src]

pub fn new_dir() -> Result<Self>[src]

Create a temporary directory.

pub fn new_dir_in<P: AsRef<Path>>(directory: P) -> Result<Self>[src]

Create a new temporary directory in an existing directory

pub fn new_file_in<P: AsRef<Path>>(directory: P) -> Result<Self>[src]

Create a new temporary file in an existing directory

pub fn new_file() -> Result<Self>[src]

Create a temporary file.

pub fn new_path() -> Self[src]

Create new uninitialized temporary path, i.e. a file or directory isn't created automatically

pub fn new_path_in<P: AsRef<Path>>(directory: P) -> Self[src]

Create a new uninitialized temporary path in an existing directory i.e. a file or directory isn't created automatically

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

Return this temporary file or directory as a PathBuf.

Examples

use mktemp::Temp;

let temp_dir = Temp::new_dir().unwrap();
let mut path_buf = temp_dir.to_path_buf();

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

Release ownership of the temporary file or directory.

Examples

use mktemp::Temp;
let path_buf;
{
  let mut temp_dir = Temp::new_dir().unwrap();
  path_buf = temp_dir.to_path_buf();
  temp_dir.release();
}
assert!(path_buf.exists());

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 Clone for Temp[src]

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

Performs copy-assignment from source. Read more

impl Drop for Temp[src]

impl AsRef<Path> for Temp[src]

impl Deref for Temp[src]

type Target = PathBuf

The resulting type after dereferencing.

impl DerefMut for Temp[src]

Auto Trait Implementations

impl Send for Temp

impl Sync for Temp

Blanket Implementations

impl<T> From for T[src]

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, 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> Any for T where
    T: 'static + ?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.