Struct temp_dir::TempDir [−][src]
pub struct TempDir { /* fields omitted */ }
The path of an existing writable directory in a system temporary directory.
Drop the struct to delete the directory and everything under it. Deletes symbolic links and does not follow them.
Ignores any error while deleting.
See TempDir::panic_on_cleanup_error
.
Example
use temp_dir::TempDir; let d = TempDir::new().unwrap(); // Prints "/tmp/t1a9b-0". println!("{:?}", d.path()); let f = d.child("file1"); // Prints "/tmp/t1a9b-0/file1". println!("{:?}", f); std::fs::write(&f, b"abc").unwrap(); assert_eq!( "abc", std::fs::read_to_string(&f).unwrap(), ); // Prints "/tmp/t1a9b-1". println!("{:?}", TempDir::new().unwrap().path());
Implementations
impl TempDir
[src]
impl TempDir
[src]pub fn new() -> Result<Self, Error>
[src]
Create a new empty directory in a system temporary directory.
Drop the struct to delete the directory and everything under it. Deletes symbolic links and does not follow them.
Ignores any error while deleting.
See TempDir::panic_on_cleanup_error
.
Errors
Returns Err
when it fails to create the directory.
Example
// Prints "/tmp/t1a9b-0". println!("{:?}", temp_dir::TempDir::new().unwrap().path());
pub fn with_prefix(prefix: impl AsRef<str>) -> Result<Self, Error>
[src]
Create a new empty directory in a system temporary directory.
Use prefix
as the first part of the directory’s name.
Drop the struct to delete the directory and everything under it. Deletes symbolic links and does not follow them.
Ignores any error while deleting.
See TempDir::panic_on_cleanup_error
.
Errors
Returns Err
when it fails to create the directory.
Example
// Prints "/tmp/ok1a9b-0". println!("{:?}", temp_dir::TempDir::with_prefix("ok").unwrap().path());
pub fn cleanup(self) -> Result<(), Error>
[src]
Remove the directory on its contents now. Do nothing later on drop.
Errors
Returns an error if the directory exists and we fail to remove it and its contents.
#[must_use]pub fn panic_on_cleanup_error(self) -> Self
[src]
Make the struct panic on Drop if it hits an error while removing the directory or its contents.
pub fn leak(self)
[src]
Do not delete the directory or its contents.
This is useful when debugging a test.
#[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 PartialOrd<TempDir> for TempDir
[src]
impl PartialOrd<TempDir> for TempDir
[src]impl StructuralEq for TempDir
[src]
impl StructuralEq for TempDir
[src]impl StructuralPartialEq for TempDir
[src]
impl StructuralPartialEq for TempDir
[src]Auto Trait Implementations
impl RefUnwindSafe for TempDir
impl RefUnwindSafe for TempDir
impl UnwindSafe for TempDir
impl UnwindSafe for TempDir