ncro/config: replace YAML configuration file with TOML

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ifb3cf9ad9747795b44eff1ee8cd538536a6a6964
This commit is contained in:
raf 2026-05-11 13:13:00 +03:00
commit 49545fdb6b
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
20 changed files with 280 additions and 199 deletions

View file

@ -1,13 +1,17 @@
[package]
name = "ncro-config"
name = "ncro-config"
version.workspace = true
edition.workspace = true
license.workspace = true
publish = false
[dependencies]
hex.workspace = true
hex.workspace = true
humantime-serde.workspace = true
serde = { workspace = true, features = [ "derive" ] }
serde_yaml.workspace = true
thiserror.workspace = true
url.workspace = true
serde = { workspace = true, features = [ "derive" ] }
thiserror.workspace = true
toml.workspace = true
url.workspace = true
[lints]
workspace = true

View file

@ -9,7 +9,7 @@ pub enum ConfigError {
#[error("read config: {0}")]
Read(#[from] std::io::Error),
#[error("parse config: {0}")]
Parse(#[from] serde_yaml::Error),
Parse(#[from] toml::de::Error),
#[error("{0}")]
Validation(String),
}
@ -29,9 +29,9 @@ mod tests {
}
#[test]
fn parses_duration_yaml() -> Result<(), serde_yaml::Error> {
let cfg: Config = serde_yaml::from_str(
"server:\n read_timeout: 30s\ncache:\n ttl: 2h\n",
fn parses_duration_toml() -> Result<(), toml::de::Error> {
let cfg: Config = toml::from_str(
"[server]\nread_timeout = \"30s\"\n\n[cache]\nttl = \"2h\"\n",
)?;
assert_eq!(cfg.server.read_timeout.0, Duration::from_secs(30));
assert_eq!(cfg.cache.ttl.0, Duration::from_secs(7200));
@ -207,7 +207,7 @@ impl Config {
pub fn load(path: Option<&str>) -> Result<Self, ConfigError> {
let mut cfg = if let Some(path) = path.filter(|p| !p.is_empty()) {
let data = fs::read_to_string(path)?;
serde_yaml::from_str::<Self>(&data)?
toml::from_str::<Self>(&data)?
} else {
Self::default()
};