luby/crates/lb/src/fs/temp.rs
2025-06-30 19:23:44 +10:00

26 lines
635 B
Rust

use luaffi::{cdef, metatype};
use tempfile::TempDir;
/// Directory in the filesystem that is automatically deleted when it is garbage-collected.
#[derive(Debug)]
#[cdef]
pub struct lb_temp_dir(#[opaque] TempDir);
#[metatype]
impl lb_temp_dir {
pub(super) fn new(dir: TempDir) -> Self {
Self(dir)
}
/// Returns the full path of this temporary directory.
pub extern "Lua-C" fn path(&self) -> String {
self.0.path().to_string_lossy().into()
}
/// Returns the full path of this temporary directory.
#[tostring]
pub extern "Lua" fn tostring(&self) -> String {
self.path()
}
}