[][src]Struct drop_dir::DropDir

pub struct DropDir { /* fields omitted */ }

Represents a Directory that will be automatically deleted when it goes out of scope.

Example

use std::path::PathBuf;
use drop_dir::DropDir;
use std::fs::File;

let drop_dir = DropDir::new(PathBuf::from("/tmp/some/path")).unwrap();
let mut file = File::create(drop_dir.path().join("file.txt")).unwrap();
// drop_dir deleted when it goes out of scope.

Limitation

In the example above, only the last component of the drop_dir is removed. That is, the dir /tmp/some/temp/path is deleted, but /tmp/some/temp remains. Any other behavior would get complicated.

Methods

impl DropDir[src]

pub fn new(path_buf: PathBuf) -> Result<DropDir, Error>[src]

new

Constructs a new DropDir object from a PathBuf. Creates the directory at PathBuf if it does not exist (using fs::create_dir_all).

Example

let drop_dir = DropDir::new(PathBuf::from("/tmp/some/path")).unwrap();

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

path

Returns a clone of the internally held PathBuf.

Example

let path_str = drop_dir.path().to_string_lossy();

Trait Implementations

impl Drop for DropDir[src]

Auto Trait Implementations

impl RefUnwindSafe for DropDir

impl Send for DropDir

impl Sync for DropDir

impl Unpin for DropDir

impl UnwindSafe for DropDir

Blanket Implementations

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

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

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

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.