mirror of
				https://github.com/rust-lang/rust.git
				synced 2025-10-31 04:57:19 +00:00 
			
		
		
		
	 4d9b476bb1
			
		
	
	
		4d9b476bb1
		
	
	
	
	
		
			
			bumpalo 3.12.1 (yanked) * updated to 3.13.0 tokio 1.8.4 - https://rustsec.org/advisories/RUSTSEC-2023-0001 * updated to 1.28.2 remove_dir_all 0.5.3 - https://rustsec.org/advisories/RUSTSEC-2023-0018 * removed by using the standard library function in `rust-installer` instead and updating to `tempfile@3.5.0` (which also removes the dependency).
		
			
				
	
	
		
			35 lines
		
	
	
		
			857 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
		
			857 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
| use std::mem::ManuallyDrop;
 | |
| use std::path::Path;
 | |
| use tempfile::TempDir;
 | |
| 
 | |
| /// This is used to avoid TempDir being dropped on error paths unintentionally.
 | |
| #[derive(Debug)]
 | |
| pub struct MaybeTempDir {
 | |
|     dir: ManuallyDrop<TempDir>,
 | |
|     // Whether the TempDir should be deleted on drop.
 | |
|     keep: bool,
 | |
| }
 | |
| 
 | |
| impl Drop for MaybeTempDir {
 | |
|     fn drop(&mut self) {
 | |
|         // SAFETY: We are in the destructor, and no further access will
 | |
|         // occur.
 | |
|         let dir = unsafe { ManuallyDrop::take(&mut self.dir) };
 | |
|         if self.keep {
 | |
|             let _ = dir.into_path();
 | |
|         }
 | |
|     }
 | |
| }
 | |
| 
 | |
| impl AsRef<Path> for MaybeTempDir {
 | |
|     fn as_ref(&self) -> &Path {
 | |
|         self.dir.path()
 | |
|     }
 | |
| }
 | |
| 
 | |
| impl MaybeTempDir {
 | |
|     pub fn new(dir: TempDir, keep_on_drop: bool) -> MaybeTempDir {
 | |
|         MaybeTempDir { dir: ManuallyDrop::new(dir), keep: keep_on_drop }
 | |
|     }
 | |
| }
 |