use mlua::{FromLua, Value}; use crate::{handlers::staticfile::StaticFile, request::Request, response::Response}; mod staticfile; pub(super) trait Handle { async fn handle(&self, request: Request) -> Result; } #[derive(Debug, thiserror::Error)] pub enum Error { #[error("unsupported method")] Unsupported, #[error("static file handler error: {0}")] StaticFile(#[from] staticfile::Error), } #[derive(Debug, Clone)] pub enum Handlers { StaticFile(StaticFile), } impl FromLua for Handlers { fn from_lua(value: Value, lua: &mlua::Lua) -> mlua::Result { match value { Value::Table(table) => match table.get::("handler")?.as_str() { "staticfile" => Ok(Self::StaticFile(StaticFile::from_lua( Value::Table(table.clone()), lua, )?)), _ => Err(mlua::Error::runtime("unknown handler")), }, _ => Err(mlua::Error::runtime("expected table")), } } }