pub struct TempDir { /* private fields */ }Expand description
Manages a temporary directory that can be used by tests. Supports creating files in the directory. Once the value is dropped the entire directory and its contents are deleted.
§Examples
use tux::temp_dir;
let dir = temp_dir();
dir.create_file("test.txt", "some content");
println!("{:?}", dir.path());
println!("{}", dir.path_str());
// this will delete the directory and its contents
drop(dir);Implementations§
Source§impl TempDir
impl TempDir
Sourcepub fn create_new() -> TempDir
pub fn create_new() -> TempDir
Creates a new instance. For convenience, use the alias temp_dir.
Sourcepub fn create_file<S: AsRef<[u8]>>(&self, name: &str, contents: S) -> PathBuf
pub fn create_file<S: AsRef<[u8]>>(&self, name: &str, contents: S) -> PathBuf
Creates a file in the temporary directory. Returns the absolute path to the created file.
The file name can contain path components for intermediate
directories, and those will be created as necessary.
§Errors
- This will panic if attempting to create files outside the temporary directory.
- This will panic if the file creation or writing fails.
Auto Trait Implementations§
impl Freeze for TempDir
impl RefUnwindSafe for TempDir
impl Send for TempDir
impl Sync for TempDir
impl Unpin for TempDir
impl UnwindSafe for TempDir
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more