add dynamic config

This commit is contained in:
2025-04-30 23:38:45 +02:00
parent 1065bd1956
commit ce49dd6e3d
2 changed files with 32 additions and 1 deletions

View File

@@ -7,6 +7,6 @@ edition = "2024"
http-body-util = "0.1.3" http-body-util = "0.1.3"
hyper = { version = "1.6.0", features = ["full"] } hyper = { version = "1.6.0", features = ["full"] }
hyper-util = { version = "0.1.11", 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"] } tokio = { version = "1.44.2", features = ["full"] }
toml = "0.8.22" toml = "0.8.22"

View File

@@ -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: "<host>:<port>"
}
}