generated from lucas/rust-template
Fix compiler issues
Apparently some changes in mlua that weren't caught during the update.
This commit is contained in:
parent
6d7ccda449
commit
c73f26bd67
2 changed files with 9 additions and 9 deletions
|
@ -4,14 +4,14 @@ use mlua::IntoLua;
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Converts a `serde_json::Value` to a `mlua::Value`.
|
||||
fn json_to_lua(value: serde_json::Value, lua: &mlua::Lua) -> mlua::Result<mlua::Value<'_>> {
|
||||
fn json_to_lua(value: serde_json::Value, lua: &mlua::Lua) -> mlua::Result<mlua::Value> {
|
||||
match value {
|
||||
serde_json::Value::Null => Ok(mlua::Value::Nil),
|
||||
serde_json::Value::Bool(value) => Ok(mlua::Value::Boolean(value)),
|
||||
serde_json::Value::Number(value) => match value.as_f64() {
|
||||
Some(number) => Ok(mlua::Value::Number(number)),
|
||||
None => Err(mlua::Error::ToLuaConversionError {
|
||||
from: "serde_json::Value::Number",
|
||||
from: String::from("serde_json::Value::Number"),
|
||||
to: "Number",
|
||||
message: Some("Number cannot be represented by a floating-point type".into()),
|
||||
}),
|
||||
|
@ -52,8 +52,8 @@ pub(crate) struct ApiEvent {
|
|||
pub status: u16,
|
||||
}
|
||||
|
||||
impl<'lua> IntoLua<'lua> for ApiEvent {
|
||||
fn into_lua(self, lua: &'lua mlua::Lua) -> mlua::Result<mlua::Value<'lua>> {
|
||||
impl IntoLua for ApiEvent {
|
||||
fn into_lua(self, lua: &mlua::Lua) -> mlua::Result<mlua::Value> {
|
||||
let headers = lua.create_table_with_capacity(0, self.headers.len())?;
|
||||
for (k, v) in self.headers {
|
||||
let k = lua.create_string(k)?;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::sync::mpsc::Receiver;
|
||||
|
||||
use color_eyre::Result;
|
||||
use color_eyre::{eyre, Result};
|
||||
use mlua::{Function, IntoLua as _, Lua, LuaSerdeExt};
|
||||
use tokio::sync::mpsc::UnboundedSender;
|
||||
|
||||
|
@ -96,23 +96,23 @@ pub fn worker(
|
|||
Event::Webhook(data) => {
|
||||
tracing::trace!(id = data.topic, "Received webhook event");
|
||||
let data = lua.to_value(&data)?;
|
||||
event_fn.call::<_, ()>(("webhook", data))?
|
||||
event_fn.call(("webhook", data))?
|
||||
}
|
||||
Event::Api(data) => {
|
||||
tracing::trace!(id = data.id, status = data.status, "Received api event");
|
||||
let data = data.into_lua(&lua)?;
|
||||
event_fn.call::<_, ()>(("api", data))?
|
||||
event_fn.call(("api", data))?
|
||||
}
|
||||
Event::Error(data) => {
|
||||
tracing::trace!(id = data.id, message = data.message, "Received error event");
|
||||
let data = lua.to_value(&data)?;
|
||||
event_fn.call::<_, ()>(("error", data))?
|
||||
event_fn.call(("error", data))?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})?;
|
||||
}).map_err(|e| eyre::eyre!("{:?}", e))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue