[−][src]Struct tempfile::TempPath
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]
impl TempPath
pub fn close(self) -> Result<()>
[src]
pub fn close(self) -> Result<()>
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]
pub fn persist<P: AsRef<Path>>(
self,
new_path: P
) -> Result<(), PathPersistError>
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]
pub fn persist_noclobber<P: AsRef<Path>>(
self,
new_path: P
) -> Result<(), PathPersistError>
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]
impl AsRef<Path> for TempPath
impl AsRef<OsStr> for TempPath
[src]
impl AsRef<OsStr> for TempPath
impl Drop for TempPath
[src]
impl Drop for TempPath
impl Debug for TempPath
[src]
impl Debug for TempPath
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Deref for TempPath
[src]
impl Deref for TempPath
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 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]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,