[][src]Struct tempfile::TempPath

pub struct TempPath { /* fields omitted */ }

A path to a named temporary file without an open file handle.

This is useful when the temporary file needs to be used by a child process, for example.

When dropped, the temporary file is deleted.

Methods

impl TempPath
[src]

Close and remove the temporary file.

Use this if you want to detect errors in deleting the file.

Errors

If the file cannot be deleted, Err is returned.

Examples

use tempfile::NamedTempFile;

let file = NamedTempFile::new()?;

// Close the file, but keep the path to it around.
let path = file.into_temp_path();

// By closing the `TempPath` explicitly, we can check that it has
// been deleted successfully. If we don't close it explicitly, the
// file will still be deleted when `file` goes out of scope, but we
// won't know whether deleting the file succeeded.
path.close()?;

Persist the temporary file at the target path.

If a file exists at the target path, persist will atomically replace it. If this method fails, it will return self in the resulting PathPersistError.

Note: Temporary files cannot be persisted across filesystems.

Security

Only use this method if you're positive that a temporary file cleaner won't have deleted your file. Otherwise, you might end up persisting an attacker controlled file.

Errors

If the file cannot be moved to the new location, Err is returned.

Examples

use tempfile::NamedTempFile;

let mut file = NamedTempFile::new()?;
writeln!(file, "Brian was here. Briefly.")?;

let path = file.into_temp_path();
path.persist("./saved_file.txt")?;

Persist the temporary file at the target path iff no file exists there.

If a file exists at the target path, fail. If this method fails, it will return self in the resulting PathPersistError.

Note: Temporary files cannot be persisted across filesystems. Also Note: This method is not atomic. It can leave the original link to the temporary file behind.

Security

Only use this method if you're positive that a temporary file cleaner won't have deleted your file. Otherwise, you might end up persisting an attacker controlled file.

Errors

If the file cannot be moved to the new location or a file already exists there, Err is returned.

Examples

use tempfile::NamedTempFile;

let mut file = NamedTempFile::new()?;
writeln!(file, "Brian was here. Briefly.")?;

let path = file.into_temp_path();
path.persist_noclobber("./saved_file.txt")?;

Trait Implementations

impl AsRef<Path> for TempPath
[src]

Performs the conversion.

impl AsRef<OsStr> for TempPath
[src]

Performs the conversion.

impl Drop for TempPath
[src]

Executes the destructor for this type. Read more

impl Debug for TempPath
[src]

Formats the value using the given formatter. Read more

impl Deref for TempPath
[src]

The resulting type after dereferencing.

Dereferences the value.

Auto Trait Implementations

impl Send for TempPath

impl Sync for TempPath

Blanket Implementations

impl<T> From for T
[src]

Performs the conversion.

impl<T, U> Into for T where
    U: From<T>, 
[src]

Performs the conversion.

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<T> Borrow for T where
    T: ?Sized
[src]

Immutably borrows from an owned value. Read more

impl<T> Any for T where
    T: 'static + ?Sized
[src]

🔬 This is a nightly-only experimental API. (get_type_id)

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more

impl<T> BorrowMut for T where
    T: ?Sized
[src]

Mutably borrows from an owned value. Read more

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.