1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//! A Koto language module for working with temporary files

use koto_runtime::{
    core_lib::io::{map_io_err, File},
    KMap,
};
use tempfile::NamedTempFile;

pub fn make_module() -> KMap {
    let result = KMap::with_type("temp_file");

    result.add_fn("temp_file", {
        |_| match NamedTempFile::new().map_err(map_io_err) {
            Ok(file) => {
                let path = file.path().to_path_buf();
                Ok(File::system_file(file, path))
            }
            Err(e) => Err(e),
        }
    });

    result
}