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
impl TmpDir
Sourcepub fn unique_path(&self) -> PathBuf
pub fn unique_path(&self) -> PathBuf
Generate a new unique path in the temporary directory.
Sourcepub fn write_file<P, C>(&self, path: P, contents: C) -> Result<()>
pub fn write_file<P, C>(&self, path: P, contents: C) -> Result<()>
Write to a file (or create it if it doesn’t exist)
in the temporary directory. Akin to fs::write
.
Sourcepub fn read_file<P>(&self, path: P) -> Result<Vec<u8>>
pub fn read_file<P>(&self, path: P) -> Result<Vec<u8>>
Read a file in the temporary directory. Akin to
fs::read
.
Sourcepub fn create_dir<P>(&self, path: P) -> Result<()>
pub fn create_dir<P>(&self, path: P) -> Result<()>
Create a directory inside the temporary directory.
Akin to fs::create_dir
.
Sourcepub fn create_dir_all<P>(&self, path: P) -> Result<()>
pub fn create_dir_all<P>(&self, path: P) -> Result<()>
Create a directory and all of its parent components
if they are missing. Akin to fs::create_dir_all
.
Sourcepub fn create_file<P>(&self, path: P) -> Result<File>
pub fn create_file<P>(&self, path: P) -> Result<File>
Create a file in the temporary directory and open it
in write-only mode. Akin to File::create
.
Sourcepub fn open_readable<P>(&self, path: P) -> Result<File>
pub fn open_readable<P>(&self, path: P) -> Result<File>
Open a file in the temporary directory in read-only
mode. Akin to File::open
.
Sourcepub fn open_writable<P>(&self, path: P) -> Result<File>
pub fn open_writable<P>(&self, path: P) -> Result<File>
Open a file in the temporary directory in write-only mode.
Sourcepub fn open_with_opts<P>(&self, opts: &mut OpenOptions, path: P) -> Result<File>
pub fn open_with_opts<P>(&self, opts: &mut OpenOptions, path: P) -> Result<File>
Open a file in the temporary directory using the
provided OpenOptions. Akin to fs::OpenOptions::open
.
Sourcepub fn metadata<P>(&self, path: P) -> Result<Metadata>
pub fn metadata<P>(&self, path: P) -> Result<Metadata>
Get metadata for the given path. Akin to fs::metadata
.
Sourcepub fn exists<P>(&self, path: P) -> bool
pub fn exists<P>(&self, path: P) -> bool
Check if a path exists in the current directory. Akin
to Path::exists
.
Sourcepub fn read_dir<P>(&self, path: P) -> Result<ReadDir>
pub fn read_dir<P>(&self, path: P) -> Result<ReadDir>
Read temporary directory. Akin to fs::read_dir
.
Sourcepub fn remove_file<P>(&self, path: P) -> Result<()>
pub fn remove_file<P>(&self, path: P) -> Result<()>
Remove a file in the current directory. Akin to
fs::remove_file
.
Sourcepub fn remove_dir<P>(&self, path: P) -> Result<()>
pub fn remove_dir<P>(&self, path: P) -> Result<()>
Remove a directory in the current directory. Akin to
fs::remove_dir
.
Sourcepub fn remove_dir_all<P>(&self, path: P) -> Result<()>
pub fn remove_dir_all<P>(&self, path: P) -> Result<()>
Remove a directory and all its contents in the current
directory. Akin to fs::remove_dir_all
.