mod private
{
#[ cfg( feature = "enabled" ) ]
extern crate std;
#[ cfg( feature = "enabled" ) ]
use std::path::PathBuf;
#[ cfg( feature = "enabled" ) ]
use std::fs;
#[ cfg( feature = "enabled" ) ]
use std::io;
#[ cfg( feature = "enabled" ) ]
#[ derive( Debug ) ]
pub struct TempDir
{
pub base_path : PathBuf,
pub prefix_path : PathBuf,
pub postfix_path : PathBuf,
created_path : Option< PathBuf >,
}
#[ cfg( feature = "enabled" ) ]
impl Default for TempDir
{
fn default() -> Self
{
Self::new()
}
}
#[ cfg( feature = "enabled" ) ]
impl TempDir
{
#[ must_use ]
pub fn new() -> Self
{
Self
{
base_path : PathBuf::new(),
prefix_path : PathBuf::new(),
postfix_path : PathBuf::new(),
created_path : None,
}
}
#[ must_use ]
pub fn full_path( &self ) -> PathBuf
{
let mut path = PathBuf::new();
if !self.base_path.as_os_str().is_empty()
{
path.push( &self.base_path );
}
if !self.prefix_path.as_os_str().is_empty()
{
path.push( &self.prefix_path );
}
if !self.postfix_path.as_os_str().is_empty()
{
path.push( &self.postfix_path );
}
path
}
pub fn create( &mut self ) -> io::Result< PathBuf >
{
let path = self.full_path();
fs::create_dir( &path )?;
self.created_path = Some( path.clone() );
Ok( path )
}
pub fn create_all( &mut self ) -> io::Result< PathBuf >
{
let path = self.full_path();
fs::create_dir_all( &path )?;
self.created_path = Some( path.clone() );
Ok( path )
}
}
#[ cfg( feature = "enabled" ) ]
impl Drop for TempDir
{
fn drop( &mut self )
{
if let Some( ref path ) = self.created_path
{
let _ = fs::remove_dir_all( path );
}
}
}
}
#[ allow( unused_imports ) ]
pub mod own
{
use super :: *;
#[ doc( inline ) ]
pub use orphan :: *;
}
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use own :: *;
#[ allow( unused_imports ) ]
pub mod orphan
{
use super :: *;
#[ doc( inline ) ]
pub use exposed :: *;
}
#[ allow( unused_imports ) ]
pub mod exposed
{
use super :: *;
#[ doc( inline ) ]
pub use prelude :: *;
#[ cfg( feature = "enabled" ) ]
#[ doc( inline ) ]
pub use super::private::TempDir;
}
#[ allow( unused_imports ) ]
pub mod prelude
{
use super :: *;
}