diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2020-06-20 12:44:59 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2020-06-20 12:44:59 +0100 |
commit | 37565e21534ec83eda0088d55d1680f7e71ab6f1 (patch) | |
tree | b2bede74670daa3886a460ccbcadb06ca11fe5bb | |
parent | f70647d4f57c2adf93daec84c2f510241b60f70d (diff) | |
download | subplot-37565e21534ec83eda0088d55d1680f7e71ab6f1.tar.gz |
feat: Ensure keys in bindings files are case insensitive
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
-rw-r--r-- | Cargo.lock | 13 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/bindings.rs | 14 |
3 files changed, 25 insertions, 3 deletions
@@ -557,6 +557,17 @@ dependencies = [ ] [[package]] +name = "serde-aux" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "serde_derive" version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -645,6 +656,7 @@ dependencies = [ "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "roadmap 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", + "serde-aux 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)", "serde_yaml 0.8.11 (registry+https://github.com/rust-lang/crates.io-index)", "structopt 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -958,6 +970,7 @@ dependencies = [ "checksum ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bfa8506c1de11c9c4e4c38863ccbe02a305c8188e85a05a784c9e11e1c3910c8" "checksum same-file 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "585e8ddcedc187886a30fa705c47985c3fa88d06624095856b36ca0b82ff4421" "checksum serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" +"checksum serde-aux 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ae50f53d4b01e854319c1f5b854cd59471f054ea7e554988850d3f36ca1dc852" "checksum serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64" "checksum serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)" = "48c575e0cc52bdd09b47f330f646cf59afc586e9c4e3ccd6fc1f625b8ea1dad7" "checksum serde_yaml 0.8.11 (registry+https://github.com/rust-lang/crates.io-index)" = "691b17f19fc1ec9d94ec0b5864859290dff279dbd7b03f017afda54eb36c3c35" @@ -25,6 +25,7 @@ regex = "1" serde_yaml = "0.8.11" serde_json = "1.0" serde = { version = "1.0.101", features = ["derive"] } +serde-aux = "0.6.1" chrono = "0.4" thiserror = "1" anyhow = "1" diff --git a/src/bindings.rs b/src/bindings.rs index 40ef0b4..84b331b 100644 --- a/src/bindings.rs +++ b/src/bindings.rs @@ -5,6 +5,7 @@ use super::StepKind; use crate::{Result, SubplotError}; use serde::Deserialize; +use serde_aux::prelude::*; use std::fs::File; use std::io::Read; @@ -257,6 +258,13 @@ struct ParsedBinding { regex: Option<bool>, } +#[derive(Debug, Deserialize)] +#[serde(transparent)] +struct ParsedBindingWrapper { + #[serde(deserialize_with = "deserialize_struct_case_insensitive")] + binding: ParsedBinding, +} + impl Bindings { /// Create a new, empty set of bindings. pub fn new() -> Bindings { @@ -280,9 +288,9 @@ impl Bindings { /// Add bindings from a YAML string pub fn add_from_yaml(&mut self, yaml: &str) -> Result<()> { - let bindings: Vec<ParsedBinding> = serde_yaml::from_str(yaml)?; - for b in bindings { - self.add(from_hashmap(&b)?); + let bindings: Vec<ParsedBindingWrapper> = serde_yaml::from_str(yaml)?; + for wrapper in bindings { + self.add(from_hashmap(&wrapper.binding)?); } Ok(()) } |