mirror of
https://github.com/lune-org/lune.git
synced 2024-12-13 13:30:38 +00:00
31 lines
1,007 B
Rust
31 lines
1,007 B
Rust
use mlua::prelude::*;
|
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
pub struct FsWriteOptions {
|
|
pub(crate) overwrite: bool,
|
|
}
|
|
|
|
impl<'lua> FromLua<'lua> for FsWriteOptions {
|
|
fn from_lua(value: LuaValue<'lua>, _: &'lua Lua) -> LuaResult<Self> {
|
|
Ok(match value {
|
|
LuaValue::Nil => Self { overwrite: false },
|
|
LuaValue::Boolean(b) => Self { overwrite: b },
|
|
LuaValue::Table(t) => {
|
|
let overwrite: Option<bool> = t.get("overwrite")?;
|
|
Self {
|
|
overwrite: overwrite.unwrap_or(false),
|
|
}
|
|
}
|
|
_ => {
|
|
return Err(LuaError::FromLuaConversionError {
|
|
from: value.type_name(),
|
|
to: "FsWriteOptions",
|
|
message: Some(format!(
|
|
"Invalid write options - expected boolean or table, got {}",
|
|
value.type_name()
|
|
)),
|
|
})
|
|
}
|
|
})
|
|
}
|
|
}
|