use std::str::FromStr; use mlua::{ExternalError, ExternalResult, UserData, Value}; #[derive(Clone, Copy, Default)] pub struct Color(pub ratatui::style::Color); impl TryFrom for Color { type Error = mlua::Error; fn try_from(value: Value) -> Result { Ok(Self(match value { Value::String(s) => ratatui::style::Color::from_str(&s.to_str()?).into_lua_err()?, Value::UserData(ud) => ud.borrow::()?.0, _ => Err("expected a Color".into_lua_err())?, })) } } impl UserData for Color {}