TempFile

Struct TempFile 

Source
pub struct TempFile {
    pub f: File,
    pub path: PathBuf,
    /* private fields */
}
Expand description

TempFile contains information about a created temporary file and will remove the temporary file after the object goes out of scope. This is a convenience structure over create_temp results.

Fields§

§f: File§path: PathBuf

Implementations§

Source§

impl TempFile

Source

pub fn new(pattern: &str) -> Result<Self>

new creates a new temporary file in the default directory for temporary files. The new file’s name is generated by adding a random string to the end of pattern. If pattern includes a “”, the random string replaces the last “” instead. The temporary file will be removed when the object goes out of scope.

Examples found in repository?
examples/tempfile.rs (line 8)
7fn main() {
8    let tf = TempFile::new("ggstd-*.txt").unwrap();
9    println!("{}", tf.path.to_string_lossy());
10
11    let td = TempDir::new("ggstd-").unwrap();
12    println!("{}", td.path.to_string_lossy());
13
14    let tf = TempFile::new_in_dir(&td.path, "ggstd-*.txt").unwrap();
15    println!("{}", tf.path.to_string_lossy());
16}
Source

pub fn new_in_dir(dir: &Path, pattern: &str) -> Result<Self>

new_in_dir is the same as new, except that the directory dir is used instead of the system directory for temporary files.

Examples found in repository?
examples/tempfile.rs (line 14)
7fn main() {
8    let tf = TempFile::new("ggstd-*.txt").unwrap();
9    println!("{}", tf.path.to_string_lossy());
10
11    let td = TempDir::new("ggstd-").unwrap();
12    println!("{}", td.path.to_string_lossy());
13
14    let tf = TempFile::new_in_dir(&td.path, "ggstd-*.txt").unwrap();
15    println!("{}", tf.path.to_string_lossy());
16}
Source

pub fn remove(&mut self) -> Result<()>

remove removes the file

Trait Implementations§

Source§

impl Drop for TempFile

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.