create js_into for JsValue

reason: wil be way less boilerplate for deserialization of JsValue to defined structs
This commit is contained in:
Akulij 2025-05-19 23:55:44 +05:00
parent c2e02efc47
commit eb63743714

View File

@ -27,6 +27,19 @@ impl BotFunction {
runner.run_script(&format!("{func_name}()")) runner.run_script(&format!("{func_name}()"))
} }
} }
pub trait DeserializeJS {
fn js_into<'a, T: Deserialize<'a>>(&'a self) -> ScriptResult<T>;
}
impl DeserializeJS for JsValue {
fn js_into<'a, T: Deserialize<'a>>(&'a self) -> ScriptResult<T> {
let rc = from_js(self.context(), &self)?;
Ok(rc)
}
}
// TODO: remove this function since it is suitable only for early development // TODO: remove this function since it is suitable only for early development
#[allow(clippy::print_stdout)] #[allow(clippy::print_stdout)]
fn print(s: String) { fn print(s: String) {