pub struct Builder { /* private fields */ }Expand description
Build a new Temporary Object.
§Example
use std::io::Write;
let temp = temp::Builder::new().create::<temp::File>().unwrap();
let path = temp.full();
let mut file = std::fs::File::open(&path).unwrap();
write!(file, "Hello!");
drop(temp);
assert!(!path.exists());Implementations§
Source§impl Builder
impl Builder
Sourcepub fn within(self, path: impl Into<PathBuf>) -> Self
pub fn within(self, path: impl Into<PathBuf>) -> Self
The directory the Temporary Object should reside in. If not set, defaults to /tmp.
Sourcepub fn name(self, name: impl Into<String>) -> Self
pub fn name(self, name: impl Into<String>) -> Self
The name of the Temporary Object. If not set, uses a randomized, unique string.
Sourcepub fn extension(self, extension: impl Into<String>) -> Self
pub fn extension(self, extension: impl Into<String>) -> Self
Set an optional extension to the Object.
Sourcepub fn make(self, make_object: bool) -> Self
pub fn make(self, make_object: bool) -> Self
Whether to create the Object on create(). By default, the object is created.
Sourcepub fn create<T: BuilderCreate + Object + 'static>(self) -> Result<Temp, Error>
pub fn create<T: BuilderCreate + Object + 'static>(self) -> Result<Temp, Error>
Create the Object, consuming the Builder. The Object is passed as a Template to this function.
§Examples
Create a new temporary file as /tmp/new_file
let file = temp::Builder::new().name("new_file").create::<temp::File>().unwrap();
assert!(std::path::Path::new("/tmp/new_file").exists());Create a new temporary directory in the current directory
temp::Builder::new().within("").create::<temp::Directory>().unwrap();Trait Implementations§
Auto Trait Implementations§
impl Freeze for Builder
impl RefUnwindSafe for Builder
impl Send for Builder
impl Sync for Builder
impl Unpin for Builder
impl UnwindSafe for Builder
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more