use std::fmt::Debug; use automation_cast::Cast; use dyn_clone::DynClone; use mlua::ObjectLike; use crate::event::OnMqtt; #[async_trait::async_trait] pub trait LuaDeviceCreate { type Config; type Error; async fn create(config: Self::Config) -> Result where Self: Sized; } pub trait Device: Debug + DynClone + Sync + Send + Cast + Cast { fn get_id(&self) -> String; } impl mlua::FromLua for Box { fn from_lua(value: mlua::Value, _lua: &mlua::Lua) -> mlua::Result { match value { mlua::Value::UserData(ud) => { let ud = if ud.is::>() { ud } else { ud.call_method::<_>("__box", ())? }; let b = ud.borrow::()?.clone(); Ok(b) } _ => Err(mlua::Error::RuntimeError("Expected user data".into())), } } } impl mlua::UserData for Box {} dyn_clone::clone_trait_object!(Device);