Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/trait/drop.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ impl TempFile {
}

// When TempFile is dropped:
// 1. First, the File will be automatically closed (Drop for File)
// 2. Then our drop implementation will remove the file
// 1. First, our drop implementation will remove the file's name from the filesystem.
// 2. Then, File's drop will close the file, removing its underlying content from the disk.
impl Drop for TempFile {
fn drop(&mut self) {
// Note: File is already closed at this point
if let Err(e) = std::fs::remove_file(&self.path) {
eprintln!("Failed to remove temporary file: {}", e);
}
println!("> Dropped temporary file: {:?}", self.path);
// File's drop is implicitly called here because it is a field of this struct.
}
}

Expand Down