Struct fencryption_lib::tmp::TmpDir
source · pub struct TmpDir(_);Expand description
TmpDir is a struct to manipulate a temporary directory.
The “path” argument (in some methods) must be relative because it will be joined to the temporary directory path.
When this struct is dropped, the temporary directory itself is automatically deleted.
Implementations
sourceimpl TmpDir
impl TmpDir
pub fn new() -> Result<Self, Error>
pub fn path(&self) -> &PathBuf
sourcepub fn unique_path(&self) -> PathBuf
pub fn unique_path(&self) -> PathBuf
Generates a new unique path in the temporary directory.
sourcepub fn write_file<P, C>(&self, path: P, contents: C) -> Result<()>where
P: AsRef<Path>,
C: AsRef<[u8]>,
pub fn write_file<P, C>(&self, path: P, contents: C) -> Result<()>where
P: AsRef<Path>,
C: AsRef<[u8]>,
Writes to a file (or create it if it doesn’t exist)
in the temporary directory. See fs::write.
sourcepub fn read_file<P>(&self, path: P) -> Result<Vec<u8>>where
P: AsRef<Path>,
pub fn read_file<P>(&self, path: P) -> Result<Vec<u8>>where
P: AsRef<Path>,
Reads a file in the temporary directory. See fs::read.
sourcepub fn create_dir<P>(&self, path: P) -> Result<()>where
P: AsRef<Path>,
pub fn create_dir<P>(&self, path: P) -> Result<()>where
P: AsRef<Path>,
Creates a directory inside the temporary directory.
See fs::create_dir.
sourcepub fn create_dir_all<P>(&self, path: P) -> Result<()>where
P: AsRef<Path>,
pub fn create_dir_all<P>(&self, path: P) -> Result<()>where
P: AsRef<Path>,
Creates a directory and all of its parent if they are
missing (inside the temporary directory). See
fs::create_dir_all.
sourcepub fn create_file<P>(&self, path: P) -> Result<File>where
P: AsRef<Path>,
pub fn create_file<P>(&self, path: P) -> Result<File>where
P: AsRef<Path>,
Creates a file in the temporary directory. See
File::create.
sourcepub fn open_file<P>(&self, path: P) -> Result<File>where
P: AsRef<Path>,
pub fn open_file<P>(&self, path: P) -> Result<File>where
P: AsRef<Path>,
Opens a file in the temporary directory. See
File::open.
sourcepub fn open_file_with_opts<P>(
&self,
opts: &mut OpenOptions,
path: P
) -> Result<File>where
P: AsRef<Path>,
pub fn open_file_with_opts<P>(
&self,
opts: &mut OpenOptions,
path: P
) -> Result<File>where
P: AsRef<Path>,
Opens a file in the temporary directory using the
provided OpenOptions. See fs::OpenOptions::open.
sourcepub fn metadata<P>(&self, path: P) -> Result<Metadata>where
P: AsRef<Path>,
pub fn metadata<P>(&self, path: P) -> Result<Metadata>where
P: AsRef<Path>,
Gets metadata for the given path. Akin to fs::metadata.
sourcepub fn exists<P>(&self, path: P) -> boolwhere
P: AsRef<Path>,
pub fn exists<P>(&self, path: P) -> boolwhere
P: AsRef<Path>,
Checks if a path exists in the current directory. Akin
to Path::exists.
sourcepub fn read_dir(&self) -> Result<ReadDir>
pub fn read_dir(&self) -> Result<ReadDir>
Reads temporary directory. Akin to fs::read_dir.