Radish alpha
r
rad:zwTxygwuz5LDGBq255RA2CbNGrz8
Radicle CI broker
Radicle
Git
chore: switch serde YAML parsing to serde-norway
Lars Wirzenius committed 7 months ago
commit 16e534d2fb1f5ad0fdba3669f2f4cc206da297ec
parent d981727
7 files changed +38 -47
modified Cargo.lock
@@ -1408,16 +1408,6 @@ dependencies = [
]

[[package]]
-
name = "libyml"
-
version = "0.0.5"
-
source = "registry+https://github.com/rust-lang/crates.io-index"
-
checksum = "3302702afa434ffa30847a83305f0a69d6abd74293b6554c18ec85c7ef30c980"
-
dependencies = [
-
 "anyhow",
-
 "version_check",
-
]
-

-
[[package]]
name = "libz-sys"
version = "1.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2005,7 +1995,7 @@ dependencies = [
 "rss",
 "serde",
 "serde_json",
-
 "serde_yml",
+
 "serde_norway",
 "sqlite",
 "sqlite3-sys",
 "subplot-build",
@@ -2390,28 +2380,26 @@ dependencies = [
]

[[package]]
-
name = "serde_path_to_error"
-
version = "0.1.17"
+
name = "serde_norway"
+
version = "0.9.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
-
checksum = "59fab13f937fa393d08645bf3a84bdfe86e296747b506ada67bb15f10f218b2a"
+
checksum = "e408f29489b5fd500fab51ff1484fc859bb655f32c671f307dcd733b72e8168c"
dependencies = [
+
 "indexmap",
 "itoa",
+
 "ryu",
 "serde",
+
 "unsafe-libyaml-norway",
]

[[package]]
-
name = "serde_yml"
-
version = "0.0.12"
+
name = "serde_path_to_error"
+
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
-
checksum = "59e2dd588bf1597a252c3b920e0143eb99b0f76e4e082f4c92ce34fbc9e71ddd"
+
checksum = "59fab13f937fa393d08645bf3a84bdfe86e296747b506ada67bb15f10f218b2a"
dependencies = [
-
 "indexmap",
 "itoa",
-
 "libyml",
-
 "memchr",
-
 "ryu",
 "serde",
-
 "version_check",
]

[[package]]
@@ -3094,6 +3082,12 @@ dependencies = [
]

[[package]]
+
name = "unsafe-libyaml-norway"
+
version = "0.2.15"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "b39abd59bf32521c7f2301b52d05a6a2c975b6003521cbd0c6dc1582f0a22104"
+

+
[[package]]
name = "url"
version = "2.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
modified Cargo.toml
@@ -25,7 +25,7 @@ regex = "1.10.5"
rss = "2.0.9"
serde = { version = "1.0.204", features = ["derive"] }
serde_json = "1.0.121"
-
serde_yml = "0.0.12"
+
serde_norway = "0.9.42"
sqlite = "0.32.0"
sqlite3-sys = "0.15.0"
subplotlib = "0.12.0"
modified src/adapter.rs
@@ -82,7 +82,7 @@ impl Adapters {
pub struct Adapter {
    bin: PathBuf,
    env: HashMap<String, String>,
-
    config: HashMap<String, serde_yml::Value>,
+
    config: HashMap<String, serde_norway::Value>,
    config_env: Option<String>,
}

@@ -109,7 +109,7 @@ impl Adapter {
        self
    }

-
    pub fn with_config(mut self, config: HashMap<String, serde_yml::Value>) -> Self {
+
    pub fn with_config(mut self, config: HashMap<String, serde_norway::Value>) -> Self {
        self.config = config;
        self
    }
@@ -122,7 +122,8 @@ impl Adapter {
    fn write_adapter_config(&self, tmpdir: &TempDir) -> Result<PathBuf, AdapterError> {
        let filename = tmpdir.path().join("adapter.yaml");

-
        let yaml = serde_yml::to_string(&self.config).map_err(AdapterError::AdapterConfigToYaml)?;
+
        let yaml =
+
            serde_norway::to_string(&self.config).map_err(AdapterError::AdapterConfigToYaml)?;
        logger::adapter_temp_config(&filename, &yaml);
        std::fs::write(&filename, yaml.as_bytes()).map_err(AdapterError::AdapterConfigWrite)?;

@@ -442,7 +443,7 @@ pub enum AdapterError {

    /// Can't serialize adapter configuration to YAML.
    #[error("can't convert adapter configuration to YAML")]
-
    AdapterConfigToYaml(#[source] serde_yml::Error),
+
    AdapterConfigToYaml(#[source] serde_norway::Error),

    /// Can't write adapter config.
    #[error("failed to write adapter configuration")]
modified src/config.rs
@@ -65,7 +65,7 @@ impl Config {
    pub fn load(filename: &Path) -> Result<Self, ConfigError> {
        let config =
            std::fs::read(filename).map_err(|e| ConfigError::ReadConfig(filename.into(), e))?;
-
        let config: Config = serde_yml::from_slice(&config)
+
        let config: Config = serde_norway::from_slice(&config)
            .map_err(|e| ConfigError::ParseConfig(filename.into(), e))?;
        config.check(filename)?;
        Ok(config)
@@ -147,7 +147,7 @@ pub struct AdapterSpec {
    /// to a temporary file. The environment variable named in
    /// `config_env` is set to the path of the temporary file.
    #[serde(default)]
-
    config: HashMap<String, serde_yml::Value>,
+
    config: HashMap<String, serde_norway::Value>,

    config_env: Option<String>,
}
@@ -157,7 +157,7 @@ impl AdapterSpec {
        self.config_env.as_deref()
    }

-
    pub fn config(&self) -> &HashMap<String, serde_yml::Value> {
+
    pub fn config(&self) -> &HashMap<String, serde_norway::Value> {
        &self.config
    }

@@ -199,7 +199,7 @@ pub enum ConfigError {

    /// Can't parse config file as YAML.
    #[error("failed to parse configuration file as YAML: {0}")]
-
    ParseConfig(PathBuf, #[source] serde_yml::Error),
+
    ParseConfig(PathBuf, #[source] serde_norway::Error),

    /// Can't convert configuration into JSON.
    #[error("failed to convert configuration into JSON")]
@@ -230,7 +230,7 @@ max_run_time: 1min
...
"#;

-
        let cfg: Config = serde_yml::from_str(YAML).unwrap();
+
        let cfg: Config = serde_norway::from_str(YAML).unwrap();
        assert_eq!(cfg.max_run_time(), Duration::from_secs(60));
    }

@@ -245,7 +245,7 @@ db: "foo.db"
...
"#;

-
        let cfg: Config = serde_yml::from_str(YAML).unwrap();
+
        let cfg: Config = serde_norway::from_str(YAML).unwrap();
        assert_eq!(cfg.max_run_time(), DEFAULT_MAX_RUN_TIME);
    }
}
modified src/filter.rs
@@ -385,8 +385,8 @@ impl Filters {
    fn from_file(filename: &Path) -> Result<Vec<EventFilter>, FilterError> {
        let data =
            std::fs::read(filename).map_err(|e| FilterError::ReadFile(filename.into(), e))?;
-
        let filters: Self =
-
            serde_yml::from_slice(&data).map_err(|e| FilterError::ParseYaml(filename.into(), e))?;
+
        let filters: Self = serde_norway::from_slice(&data)
+
            .map_err(|e| FilterError::ParseYaml(filename.into(), e))?;
        Ok(filters.filters)
    }
}
@@ -973,7 +973,7 @@ mod test {
    }

    /// This test ensures that we can deserialize a nested enum, which is only
-
    /// possible using the `serde_yml::with::singleton_map` helper on the
+
    /// possible using the `serde_norway::with::singleton_map` helper on the
    /// `EventFilter::Not` variant.
    #[test]
    fn deserialize_yaml_nested_not() {
@@ -993,15 +993,15 @@ mod test {
- !BranchCreated
- !PatchCreated
"#;
-
        let evf = serde_yml::from_str::<EventFilter>(filters);
+
        let evf = serde_norway::from_str::<EventFilter>(filters);
        assert!(evf.is_ok(), "Failed to deserialize filters: {evf:?}");
        assert_eq!(evf.unwrap(), expected);
    }

    #[quickcheck]
-
    fn yaml_roundtrip(filter: EventFilter) -> Result<bool, serde_yml::Error> {
-
        let ser = serde_yml::to_string(&filter)?;
-
        let de = serde_yml::from_str(&ser)?;
+
    fn yaml_roundtrip(filter: EventFilter) -> Result<bool, serde_norway::Error> {
+
        let ser = serde_norway::to_string(&filter)?;
+
        let de = serde_norway::from_str(&ser)?;
        Ok(filter == de)
    }

@@ -1052,5 +1052,5 @@ pub enum FilterError {
    ReadFile(PathBuf, #[source] std::io::Error),

    #[error("failed to parse YAML event filters file {0}")]
-
    ParseYaml(PathBuf, #[source] serde_yml::Error),
+
    ParseYaml(PathBuf, #[source] serde_norway::Error),
}
modified src/node_event_source.rs
@@ -115,10 +115,6 @@ pub enum NodeEventError {
    #[error("failed to parser filters file: {0}")]
    FiltersJsonFile(PathBuf, #[source] serde_json::Error),

-
    /// An error parsing YAML as filters, when read from a file.
-
    #[error("failed to parser filters file: {0}")]
-
    FiltersYamlFile(PathBuf, #[source] serde_yml::Error),
-

    /// An error parsing JSON as filters, from an in-memory string.
    #[error("failed to parser filters as JSON")]
    FiltersJsonString(#[source] serde_json::Error),
modified src/sensitive.rs
@@ -114,7 +114,7 @@ mod test_sensitive {
    #[test]
    fn ser() -> Result<(), Box<dyn std::error::Error>> {
        let s = Sensitive::new("foo");
-
        let output = serde_yml::to_string(&s)?;
+
        let output = serde_norway::to_string(&s)?;
        println!("{output:#?}");
        assert!(!output.contains("foo"));
        Ok(())
@@ -126,7 +126,7 @@ mod test_sensitive {
        struct Foo {
            secret: Sensitive,
        }
-
        let s: Foo = serde_yml::from_str("secret: foo")?;
+
        let s: Foo = serde_norway::from_str("secret: foo")?;
        assert_eq!(s.secret.data, "foo");
        Ok(())
    }