Add helper: get_tempfile()

This commit is contained in:
Matthias Beyer 2016-01-03 17:19:29 +01:00
parent adf12992bb
commit 62ced34964

View file

@ -1 +1,14 @@
use std::fs::File;
pub mod editor; pub mod editor;
pub fn get_tempfile(ext: &str) -> Option<(String, File)> {
use rand::random;
let randomname = format!("/tmp/imag-{}.{}", random::<u64>(), ext);
debug!("Attempting to create tempfile at {}", randomname);
File::create(randomname.clone())
.map_err(|e| debug!(" Error -> {}", e))
.ok()
.map(|f| (randomname, f))
}