Struct temp_dir::TempDir [−][src]
The path of an existing writable directory in a system temporary directory.
Recursively deletes the directory and its contents on drop. Ignores any error while deleting.
Example
use temp_dir::TempDir; let d = TempDir::new().unwrap(); // Prints "/tmp/t1a9b0". println!("{:?}", d.path()); let f = d.child("file1"); // Prints "/tmp/t1a9b0/file1". println!("{:?}", f); std::fs::write(&f, b"abc").unwrap(); assert_eq!( "abc", std::fs::read_to_string(&f).unwrap(), ); // Prints "/tmp/t1a9b1". println!("{:?}", TempDir::new().unwrap().path());
Implementations
impl TempDir
[src]
pub fn new() -> Result<Self, String>
[src]
Create a new empty directory in a system temporary directory.
Drop the returned struct to delete the directory and everything under it.
Errors
Returns Err
when it fails to create the directory.
Example
// Prints "/tmp/t1a9b0". println!("{:?}", temp_dir::TempDir::new().unwrap().path());
pub fn with_prefix(prefix: impl AsRef<str>) -> Result<Self, String>
[src]
Create a new empty directory in a system temporary directory.
Use prefix
as the first part of the directory’s name.
Drop the returned struct to delete the directory and everything under it.
Errors
Returns Err
when it fails to create the directory.
Example
// Prints "/tmp/ok1a9b0". println!("{:?}", temp_dir::TempDir::with_prefix("ok").unwrap().path());
#[must_use]pub fn path(&self) -> &Path
[src]
The path to the directory.
#[must_use]pub fn child(&self, name: impl AsRef<str>) -> PathBuf
[src]
The path to name
under the directory.
Trait Implementations
impl Clone for TempDir
[src]
impl Debug for TempDir
[src]
impl Drop for TempDir
[src]
impl PartialEq<TempDir> for TempDir
[src]
impl PartialOrd<TempDir> for TempDir
[src]
fn partial_cmp(&self, other: &TempDir) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl StructuralPartialEq for TempDir
[src]
Auto Trait Implementations
impl RefUnwindSafe for TempDir
impl Send for TempDir
impl Sync for TempDir
impl Unpin for TempDir
impl UnwindSafe for TempDir
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,