diff options
Diffstat (limited to 'src/server.rs')
| -rw-r--r-- | src/server.rs | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/server.rs b/src/server.rs index 4e3812f..106f9f8 100644 --- a/src/server.rs +++ b/src/server.rs @@ -12,10 +12,12 @@ use hyper_util::rt::TokioIo; use tokio::net::TcpListener; use crate::error::ReluaxError; -use crate::{table_to_html, Result}; +use crate::luax::table_to_html; +use color_eyre::Result; use rlua::Lua; pub struct Server { + port: u16, lua: Arc<Mutex<Lua>>, } @@ -23,20 +25,17 @@ struct State { lua: Arc<Mutex<Lua>>, } -static PORT: std::sync::OnceLock<u16> = std::sync::OnceLock::new(); - impl Server { pub async fn serve(port: u16) -> Result<()> { - PORT.set(port).unwrap(); - let server = Self { + port, lua: Arc::new(Mutex::new(Lua::new())), }; server.start().await } async fn start(self) -> Result<()> { - let addr = SocketAddr::from(([127, 0, 0, 1], *PORT.get().unwrap())); + let addr = SocketAddr::from(([127, 0, 0, 1], self.port)); let listener = TcpListener::bind(addr).await?; loop { |
