Expand description
§Temp
This crate implements a factory for creating Temporary Objects, currently Files and Directories, and ensuring their deletion after falling out of scope.
temp::Builder is used to create any struct that implements the temp::Object and temp::BuilderCreate trait. This crate defines two such implementations:
temp::File: usesfs::File::createandfs::remove_file.temp::Directoryusesfs::create_dir_allandfs::remove_dir_all.
All Objects are held within the Temp structure, which mediates access to the underlying Object, as well as ensuring its deletion upon leaving scope. Instances of Temp are constructed through the Builder struct containing the following member functions:
owner(Requires theuserfeature) sets the owner of the Object, ensuring it is created by this user, and also deleted by it.withindictates the path the Temporary Object is created within. By default, it will use/tmp.namedictates the name of the Temporary Object. By default, it will use a randomized string.extensiondictates an optional file extension, useful for syntax highlighting, that is appended to the name.makedictates whether the Object should actually be created upon instantiation. In cases of objects like Sockets, it may be needed to have another call, such asbindcreate the object, while still relying onTempto clean it up.
The Builder is consumed with the create call, which assembles the Temp instance. It accepts a template generic to define which instance of the Object we are creating. For example:
let file = temp::Builder::new().name("new_file").create::<temp::File>().unwrap();
assert!(std::path::Path::new("/tmp/new_file").exists());§Features
§user
The User Feature gates the Builder::owner function to allow creating/deleting the Temporary Object with a specified user mode. This is useless unless your application is SetUID.
Structs§
- Builder
- Build a new Temporary Object.
- Directory
- A temporary directory
- File
- A temporary file.
- Temp
- An instance of a Temporary Object. The Object will be deleted when the Object is dropped.
Traits§
- Builder
Create - A trait for Objects that can be created in the
temp::Builder - Object
- An object is something that exists in the filesystem.