diff --git a/README.md b/README.md index 898ab25..265aad1 100644 --- a/README.md +++ b/README.md @@ -35,16 +35,20 @@ This sample method does the following: 5. Close the directory, deleting the contents in the process. ```rust -fn write_temp_folder_with_files() -> Result<(), io::Error> { - if let Ok(dir) = TempDir::new("my_directory_prefix") { - let file_path = dir.path().join("foo.txt"); - println!("{:?}", file_path); - - let mut f = File::create(file_path)?; - f.write_all(b"Hello, world!")?; - f.sync_all()?; - dir.close()?; - } +use std::io::{self, Write}; +use std::fs::File; +use tempdir::TempDir; + +fn write_temp_folder_with_files() -> io::Result<()> { + let dir = TempDir::new("my_directory_prefix")?; + let file_path = dir.path().join("foo.txt"); + println!("{:?}", file_path); + + let mut f = File::create(file_path)?; + f.write_all(b"Hello, world!")?; + f.sync_all()?; + dir.close()?; + Ok(()) } ```