From ce49dd6e3d83eb16a7e8aacc6f939f8726c3a0c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Mekina?= Date: Wed, 30 Apr 2025 23:38:45 +0200 Subject: [PATCH] add dynamic config --- theseus-server/Cargo.toml | 2 +- theseus-server/src/config.rs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 theseus-server/src/config.rs diff --git a/theseus-server/Cargo.toml b/theseus-server/Cargo.toml index 3420f9a..3f6425f 100644 --- a/theseus-server/Cargo.toml +++ b/theseus-server/Cargo.toml @@ -7,6 +7,6 @@ edition = "2024" http-body-util = "0.1.3" hyper = { version = "1.6.0", features = ["full"] } hyper-util = { version = "0.1.11", features = ["full"] } -serde = "1.0.219" +serde = { version = "1.0.219", features = ["derive"] } tokio = { version = "1.44.2", features = ["full"] } toml = "0.8.22" diff --git a/theseus-server/src/config.rs b/theseus-server/src/config.rs new file mode 100644 index 0000000..33af1a5 --- /dev/null +++ b/theseus-server/src/config.rs @@ -0,0 +1,31 @@ +use std::net::SocketAddr; +use serde::Deserialize; + +macro_rules! def_config { + ($(config $config_id: ident + { $([$namespace: ident $struct_name: ident]$($var_id: ident = $var_type: ty),*)*$(,)? })* + ) => { + $( + #[derive(Deserialize)] + pub struct $config_id { + $(pub $namespace: $struct_name),* + } + + $( + #[derive(Deserialize)] + pub struct $struct_name { $(pub $var_id: $var_type),* } + )* + )* + } +} + +def_config! { + + config Config { + + [server Server] + bind_to = SocketAddr, // where to bind the server tcp socket in format: ":" + + } + +}