Struct temp_file::TempFile [−][src]
pub struct TempFile { /* fields omitted */ }
The path of an existing writable file in a system temporary directory.
Deletes the file on drop. Ignores errors deleting the file.
Example
use temp_file::TempFile; let t = TempFile::new() .unwrap() .with_contents(b"abc") .unwrap(); // Prints "/tmp/1a9b0". println!("{:?}", t.path()); assert_eq!( "abc", std::fs::read_to_string(t.path()).unwrap(), ); // Prints "/tmp/1a9b1". println!("{:?}", TempFile::new().unwrap().path());
Implementations
impl TempFile
[src]
impl TempFile
[src]pub fn new() -> Result<Self, Error>
[src]
Create a new empty file in a system temporary directory.
Drop the returned struct to delete the file.
Errors
Returns Err
when it fails to create the file.
Example
// Prints "/tmp/1a9b0". println!("{:?}", temp_file::TempFile::new().unwrap().path());
pub fn with_prefix(prefix: impl AsRef<str>) -> Result<Self, Error>
[src]
Create a new empty file in a system temporary directory.
Use prefix
as the first part of the file’s name.
Drop the returned struct to delete the file.
Errors
Returns Err
when it fails to create the file.
Example
// Prints "/tmp/ok1a9b0". println!("{:?}", temp_file::TempFile::with_prefix("ok").unwrap().path());
pub fn with_contents(self, contents: &[u8]) -> Result<Self, Error>
[src]
pub fn cleanup(self) -> Result<(), Error>
[src]
Remove the file now. Do nothing later on drop.
Errors
Returns an error if the file exists and we fail to remove it.
#[must_use]pub fn panic_on_cleanup_error(self) -> Self
[src]
#[must_use]
pub fn panic_on_cleanup_error(self) -> SelfMake the struct panic on Drop if it hits an error while removing the file.
pub fn leak(self)
[src]
Do not delete the file.
This is useful when debugging a test.
#[must_use]pub fn path(&self) -> &Path
[src]
#[must_use]
pub fn path(&self) -> &PathThe path to the file.
Trait Implementations
impl PartialOrd<TempFile> for TempFile
[src]
impl PartialOrd<TempFile> for TempFile
[src]impl StructuralEq for TempFile
[src]
impl StructuralEq for TempFile
[src]impl StructuralPartialEq for TempFile
[src]
impl StructuralPartialEq for TempFile
[src]Auto Trait Implementations
impl RefUnwindSafe for TempFile
impl RefUnwindSafe for TempFile
impl UnwindSafe for TempFile
impl UnwindSafe for TempFile