[][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]

pub fn close(self) -> Result<()>[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()?;

pub fn persist<P: AsRef<Path>>(
    self,
    new_path: P
) -> Result<(), PathPersistError>
[src]

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")?;

pub fn persist_noclobber<P: AsRef<Path>>(
    self,
    new_path: P
) -> Result<(), PathPersistError>
[src]

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 Drop for TempPath[src]

impl AsRef<Path> for TempPath[src]

impl AsRef<OsStr> for TempPath[src]

impl Deref for TempPath[src]

type Target = Path

The resulting type after dereferencing.

impl Debug for TempPath[src]

Auto Trait Implementations

impl Send for TempPath

impl Sync for TempPath

Blanket Implementations

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

impl<T> From for T[src]

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

type Error = !

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

The type returned in the event of a conversion error.

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

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

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

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

The type returned in the event of a conversion error.

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

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