diff options
Diffstat (limited to 'src/handler.rs')
| -rw-r--r-- | src/handler.rs | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/src/handler.rs b/src/handler.rs deleted file mode 100644 index eb4d64a..0000000 --- a/src/handler.rs +++ /dev/null @@ -1,48 +0,0 @@ -mod lua; -mod staticfile; - -use mlua::{FromLua, Value}; - -use crate::{ - handler::{lua::LuaResponse, staticfile::StaticFile}, - request::Request, - response::Response, -}; - -pub trait Handle { - fn handle(self, request: Request) -> impl Future<Output = Result<Response, Error>>; -} - -#[derive(Debug, thiserror::Error)] -pub enum Error { - #[error("unsupported method")] - Unsupported, - - #[error("static file handler error: {0}")] - StaticFile(#[from] staticfile::Error), -} - -#[derive(Debug)] -pub enum Handler { - StaticFile(StaticFile), - Lua(LuaResponse), -} - -impl FromLua for Handler { - fn from_lua(value: Value, lua: &mlua::Lua) -> mlua::Result<Self> { - match value { - Value::Table(table) => match table.get::<String>("handler")?.as_str() { - "staticfile" => Ok(Self::StaticFile(StaticFile::from_lua( - Value::Table(table.clone()), - lua, - )?)), - "lua" => Ok(Self::Lua(LuaResponse::from_lua( - Value::Table(table.clone()), - lua, - )?)), - _ => Err(mlua::Error::runtime("unknown handler")), - }, - _ => Err(mlua::Error::runtime("expected table")), - } - } -} |
