1 use std::mem::ManuallyDrop;
5 /// This is used to avoid TempDir being dropped on error paths unintentionally.
7 pub struct MaybeTempDir {
8 dir: ManuallyDrop<TempDir>,
9 // Whether the TempDir should be deleted on drop.
13 impl Drop for MaybeTempDir {
15 // SAFETY: We are in the destructor, and no further access will
17 let dir = unsafe { ManuallyDrop::take(&mut self.dir) };
24 impl AsRef<Path> for MaybeTempDir {
25 fn as_ref(&self) -> &Path {
31 pub fn new(dir: TempDir, keep_on_drop: bool) -> MaybeTempDir {
32 MaybeTempDir { dir: ManuallyDrop::new(dir), keep: keep_on_drop }