From 6bb5be5179ed46be9aea8f8b302f0c9c41c42a27 Mon Sep 17 00:00:00 2001 From: Toshit Chawda Date: Mon, 22 Jul 2024 13:54:41 -0700 Subject: [PATCH] add yaml config support --- Cargo.lock | 20 ++++++++++++++++++++ server/Cargo.toml | 1 + server/src/config.rs | 3 +++ 3 files changed, 24 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 4f62d28..92bc452 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -567,6 +567,7 @@ dependencies = [ "regex", "serde", "serde_json", + "serde_yaml", "tokio", "tokio-util", "toml", @@ -1538,6 +1539,19 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_yaml" +version = "0.9.34+deprecated" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" +dependencies = [ + "indexmap 2.2.6", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + [[package]] name = "sha1" version = "0.10.6" @@ -1918,6 +1932,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unsafe-libyaml" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" + [[package]] name = "untrusted" version = "0.9.0" diff --git a/server/Cargo.toml b/server/Cargo.toml index 30fa3f2..1a2fe83 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -19,6 +19,7 @@ log = { version = "0.4.22", features = ["serde", "std"] } regex = "1.10.5" serde = { version = "1.0.204", features = ["derive"] } serde_json = "1.0.120" +serde_yaml = "0.9.34" tokio = { version = "1.38.1", features = ["full"] } tokio-util = { version = "0.7.11", features = ["compat", "io-util", "net"] } toml = "0.8.15" diff --git a/server/src/config.rs b/server/src/config.rs index 60886f8..604a5dd 100644 --- a/server/src/config.rs +++ b/server/src/config.rs @@ -242,6 +242,7 @@ impl Config { Ok(match CLI.format { ConfigFormat::Toml => toml::to_string_pretty(self)?, ConfigFormat::Json => serde_json::to_string_pretty(self)?, + ConfigFormat::Yaml => serde_yaml::to_string(self)?, }) } @@ -249,6 +250,7 @@ impl Config { Ok(match CLI.format { ConfigFormat::Toml => toml::from_str(&string)?, ConfigFormat::Json => serde_json::from_str(&string)?, + ConfigFormat::Yaml => serde_yaml::from_str(&string)?, }) } } @@ -258,6 +260,7 @@ pub enum ConfigFormat { #[default] Toml, Json, + Yaml, } /// Server implementation of the Wisp protocol in Rust, made for epoxy.