Struct TempFile
pub struct TempFile {
pub path: PathBuf,
}Expand description
The path to a temporary file.
If the file exists when TempFile is dropped then it is automatically deleted.
§Examples
if let Some(temp_file) = TempFile::try_create("bluec") {
let temp_file_path = temp_file.path_as_str();
// Write to file at `temp_file_path`
// When `temp_file` drops, if a file exists at `temp_file_path`, the file is deleted.
}Fields§
§path: PathBufImplementations§
§impl TempFile
impl TempFile
pub fn try_create(prefix: &str) -> Option<Self>
pub fn try_create(prefix: &str) -> Option<Self>
Tries to create a unique temporary file path in the system’s temp directory.
If successful, the file will be automatically deleted when TempFile drops.
pub fn try_create_with_extension(prefix: &str, ext: &str) -> Option<Self>
pub fn try_create_with_extension(prefix: &str, ext: &str) -> Option<Self>
Tries to create a unique temporary file path in the system’s temp directory with the given file extension.
If successful, the file will be automatically deleted when TempFile drops.
pub fn path_as_str(&self) -> &str
pub fn path_as_str(&self) -> &str
The TempFile path as a &str string slice.
pub fn path_to_string(&self) -> String
pub fn path_to_string(&self) -> String
The TempFile path as a String.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TempFile
impl RefUnwindSafe for TempFile
impl Send for TempFile
impl Sync for TempFile
impl Unpin for TempFile
impl UnwindSafe for TempFile
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more