pub struct TempFileBuilder { /* private fields */ }Expand description
A builder for configuring and creating a TempFile.
Obtain one via TempFile::builder. The file name is composed as
{prefix}{random}{suffix}, where the random core is unpredictable and
collision-resistant, and the file is created with an exclusive
(O_EXCL) create so it never clobbers an existing file.
§Example
let file = TempFile::builder()
.prefix("session_")
.suffix(".tmp")
.dir(std::env::temp_dir())
.create()
.await?;
let name = file.file_path().file_name().unwrap().to_string_lossy().into_owned();
assert!(name.starts_with("session_"));
assert!(name.ends_with(".tmp"));Implementations§
Source§impl TempFileBuilder
impl TempFileBuilder
Sourcepub fn prefix<S: Into<String>>(self, prefix: S) -> Self
pub fn prefix<S: Into<String>>(self, prefix: S) -> Self
Sets the file name prefix. Defaults to atmp_.
Sourcepub fn suffix<S: Into<String>>(self, suffix: S) -> Self
pub fn suffix<S: Into<String>>(self, suffix: S) -> Self
Sets the file name suffix (for example a file extension). Defaults to empty.
Sourcepub fn dir<P: Into<PathBuf>>(self, dir: P) -> Self
pub fn dir<P: Into<PathBuf>>(self, dir: P) -> Self
Sets the directory to create the file in. Defaults to the system
temporary directory (std::env::temp_dir).
Trait Implementations§
Source§impl Clone for TempFileBuilder
impl Clone for TempFileBuilder
Source§fn clone(&self) -> TempFileBuilder
fn clone(&self) -> TempFileBuilder
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for TempFileBuilder
impl RefUnwindSafe for TempFileBuilder
impl Send for TempFileBuilder
impl Sync for TempFileBuilder
impl Unpin for TempFileBuilder
impl UnsafeUnpin for TempFileBuilder
impl UnwindSafe for TempFileBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more