pub struct TempDir { /* private fields */ }
Expand description
Wrapper over a temporary directory.
The directory will be maintained for the lifetime of the TempDir
object.
Implementations§
source§impl TempDir
impl TempDir
sourcepub fn new_with_prefix<P: AsRef<OsStr>>(prefix: P) -> Result<TempDir>
pub fn new_with_prefix<P: AsRef<OsStr>>(prefix: P) -> Result<TempDir>
Creates a new temporary directory with prefix
.
The directory will be removed when the object goes out of scope.
§Examples
let t = TempDir::new_with_prefix("/tmp/testdir").unwrap();
sourcepub fn new_in(path: &Path) -> Result<TempDir>
pub fn new_in(path: &Path) -> Result<TempDir>
Creates a new temporary directory with inside path
.
The directory will be removed when the object goes out of scope.
§Examples
let t = TempDir::new_in(Path::new("/tmp/")).unwrap();
sourcepub fn new() -> Result<TempDir>
pub fn new() -> Result<TempDir>
Creates a new temporary directory with inside $TMPDIR
if set, otherwise in /tmp
.
The directory will be removed when the object goes out of scope.
§Examples
let t = TempDir::new().unwrap();
sourcepub fn remove(&self) -> Result<()>
pub fn remove(&self) -> Result<()>
Removes the temporary directory.
Calling this is optional as when a TempDir
object goes out of scope,
the directory will be removed.
Calling remove explicitly allows for better error handling.
§Errors
This function can only be called once per object. An error is returned otherwise.
§Examples
let temp_dir = TempDir::new_with_prefix("/tmp/testdir").unwrap();
temp_dir.remove().unwrap();
Trait Implementations§
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