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]
#[must_use]pub fn panic_on_cleanup_error(self) -> Self
[src]
Make 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]
The path to the file.
Trait Implementations
impl Clone for TempFile
[src]
impl Debug for TempFile
[src]
impl Drop for TempFile
[src]
impl Eq for TempFile
[src]
impl Hash for TempFile
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for TempFile
[src]
fn cmp(&self, other: &TempFile) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<TempFile> for TempFile
[src]
impl PartialOrd<TempFile> for TempFile
[src]
fn partial_cmp(&self, other: &TempFile) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl StructuralEq 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,
pub fn borrow_mut(&mut self) -> &mut T
[src]
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,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,