Struct temp_file::TempFile [−][src]
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][−]
pub fn new() -> Result<Self, String>
[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, String>
[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, String>
[src][−]
pub fn path(&self) -> &Path
[src][−]
The path to the file.
Trait Implementations
impl Clone for TempFile
[src][+]
impl Debug for TempFile
[src][+]
impl Drop for TempFile
[src][+]
impl PartialEq<TempFile> for TempFile
[src][+]
impl PartialOrd<TempFile> for TempFile
[src][+]
impl StructuralPartialEq for TempFile
[src]
Auto Trait Implementations
impl RefUnwindSafe for TempFile
impl Send for TempFile
impl Sync for TempFile
impl Unpin for TempFile
impl UnwindSafe for TempFile
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src][+]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src][+]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src][+]
T: ?Sized,
impl<T> From<T> for T
[src][+]
impl<T, U> Into<U> for T where
U: From<T>,
[src][+]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src][+]
T: Clone,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src][+]
U: Into<T>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src][+]
U: TryFrom<T>,