Struct TmpDir

Source
pub struct TmpDir(/* private fields */);
Expand description

Handle a temporary directory.

The path parameter (present in some methods) must be relative because it will be joined to the temporary directory path.

When this struct is dropped, the temporary directory itself is automatically deleted.

Implementations§

Source§

impl TmpDir

Source

pub fn new() -> Result<Self, Error>

Create a new TmpDir instance.

Source

pub fn path(&self) -> PathBuf

Path of the temporary directory.

Source

pub fn unique_path(&self) -> PathBuf

Generate a new unique path in the temporary directory.

Source

pub fn write_file<P, C>(&self, path: P, contents: C) -> Result<()>
where P: AsRef<Path>, C: AsRef<[u8]>,

Write to a file (or create it if it doesn’t exist) in the temporary directory. Akin to fs::write.

Source

pub fn read_file<P>(&self, path: P) -> Result<Vec<u8>>
where P: AsRef<Path>,

Read a file in the temporary directory. Akin to fs::read.

Source

pub fn create_dir<P>(&self, path: P) -> Result<()>
where P: AsRef<Path>,

Create a directory inside the temporary directory. Akin to fs::create_dir.

Source

pub fn create_dir_all<P>(&self, path: P) -> Result<()>
where P: AsRef<Path>,

Create a directory and all of its parent components if they are missing. Akin to fs::create_dir_all.

Source

pub fn create_file<P>(&self, path: P) -> Result<File>
where P: AsRef<Path>,

Create a file in the temporary directory and open it in write-only mode. Akin to File::create.

Source

pub fn open_readable<P>(&self, path: P) -> Result<File>
where P: AsRef<Path>,

Open a file in the temporary directory in read-only mode. Akin to File::open.

Source

pub fn open_writable<P>(&self, path: P) -> Result<File>
where P: AsRef<Path>,

Open a file in the temporary directory in write-only mode.

Source

pub fn open_with_opts<P>(&self, opts: &mut OpenOptions, path: P) -> Result<File>
where P: AsRef<Path>,

Open a file in the temporary directory using the provided OpenOptions. Akin to fs::OpenOptions::open.

Source

pub fn metadata<P>(&self, path: P) -> Result<Metadata>
where P: AsRef<Path>,

Get metadata for the given path. Akin to fs::metadata.

Source

pub fn exists<P>(&self, path: P) -> bool
where P: AsRef<Path>,

Check if a path exists in the current directory. Akin to Path::exists.

Source

pub fn read_dir<P>(&self, path: P) -> Result<ReadDir>
where P: AsRef<Path>,

Read temporary directory. Akin to fs::read_dir.

Source

pub fn remove_file<P>(&self, path: P) -> Result<()>
where P: AsRef<Path>,

Remove a file in the current directory. Akin to fs::remove_file.

Source

pub fn remove_dir<P>(&self, path: P) -> Result<()>
where P: AsRef<Path>,

Remove a directory in the current directory. Akin to fs::remove_dir.

Source

pub fn remove_dir_all<P>(&self, path: P) -> Result<()>
where P: AsRef<Path>,

Remove a directory and all its contents in the current directory. Akin to fs::remove_dir_all.

Trait Implementations§

Source§

impl Drop for TmpDir

Source§

fn drop(&mut self)

When TmpDir is dropped, the temporary directory itself is deleted.

Auto Trait Implementations§

§

impl Freeze for TmpDir

§

impl RefUnwindSafe for TmpDir

§

impl Send for TmpDir

§

impl Sync for TmpDir

§

impl Unpin for TmpDir

§

impl UnwindSafe for TmpDir

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V