Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rust-cli/config-rs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.15.10
Choose a base ref
...
head repository: rust-cli/config-rs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.15.11
Choose a head ref
  • 5 commits
  • 5 files changed
  • 2 contributors

Commits on Mar 12, 2025

  1. Copy the full SHA
    6ca539c View commit details
  2. fix: Add support for float yaml hash keys

    MartinHowarthFlexciton committed Mar 12, 2025
    Copy the full SHA
    1ecc731 View commit details
  3. feat: Add support for float and boolean hash keys (#650)

    The `unreachable!` code at
    https://github.com/rust-cli/config-rs/blob/main/src/file/format/yaml.rs#L53
    is reachable, and this PR fixes it for two simple types: reals and
    booleans.
    
    Prior to this change you'd get this error trying to parse the following:
    ```
    thread '...' panicked at .../config-0.15.9/src/file/format/yaml.rs:53:26:
    internal error: entered unreachable code
    ```
    
    The problematic case for me turned out to be float keys:
    ```yaml
    inner_float:
        0.1: "float 0.1"
        0.2: "float 0.2"
    ```
    
    The change in this PR follows the same pattern as already exists for
    Strings and Integers - just parse them as strings and leave it up to the
    user to work out what to do with that.
    
    Personally I only need the Real support, so happy to remove the Boolean
    case if that's at all contentious.
    
    I decided not to look into whether you can craft a hash with the other
    Yaml types (below) because it's such an odd use case it didn't seam
    realistic! That said, #547
    suggests that just treating Hash as string would have avoided that
    users' problem. However, converting from these types back into the exact
    string format they were parsed in would be difficult, so it's not clear
    what the right implementation would be. So getting the simpler case
    (reals, booleans) done feels like the right sized change to make.
    ```
        Array(Array),
        Hash(Hash),
        Alias(usize),
        Null,
        BadValue,
     ```
    
    Let me know what you think! And thanks for maintaining this useful crate :)
    epage authored Mar 12, 2025
    Copy the full SHA
    aadd8c8 View commit details
  4. docs: Update changelog

    epage committed Mar 12, 2025
    Copy the full SHA
    e57efa2 View commit details
  5. chore: Release config version 0.15.11

    epage committed Mar 12, 2025
    Copy the full SHA
    532ab4d View commit details
Showing with 35 additions and 3 deletions.
  1. +8 −1 CHANGELOG.md
  2. +1 −1 Cargo.lock
  3. +1 −1 Cargo.toml
  4. +1 −0 src/file/format/yaml.rs
  5. +24 −0 tests/testsuite/file_yaml.rs
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
<!-- next-header -->
## [Unreleased] - ReleaseDate

## [0.15.11] - 2025-03-12

### Features

- Deserialize YAML real keys as strings

## [0.15.10] - 2025-03-12

### Features
@@ -573,7 +579,8 @@ update its MSRV.
Initial release.

<!-- next-url -->
[Unreleased]: https://github.com/rust-cli/config-rs/compare/v0.15.10...HEAD
[Unreleased]: https://github.com/rust-cli/config-rs/compare/v0.15.11...HEAD
[0.15.11]: https://github.com/rust-cli/config-rs/compare/v0.15.10...v0.15.11
[0.15.10]: https://github.com/rust-cli/config-rs/compare/v0.15.9...v0.15.10
[0.15.9]: https://github.com/rust-cli/config-rs/compare/v0.15.8...v0.15.9
[0.15.8]: https://github.com/rust-cli/config-rs/compare/v0.15.7...v0.15.8
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ zero_sized_map_values = "warn"

[package]
name = "config"
version = "0.15.10"
version = "0.15.11"
description = "Layered configuration system for Rust applications."
categories = ["config"]
keywords = ["config", "configuration", "settings", "env", "environment"]
1 change: 1 addition & 0 deletions src/file/format/yaml.rs
Original file line number Diff line number Diff line change
@@ -51,6 +51,7 @@ fn from_yaml_value(
yaml::Yaml::String(k) => m.insert(k.to_owned(), from_yaml_value(uri, value)?),
yaml::Yaml::Integer(k) => m.insert(k.to_string(), from_yaml_value(uri, value)?),
yaml::Yaml::Boolean(k) => m.insert(k.to_string(), from_yaml_value(uri, value)?),
yaml::Yaml::Real(k) => m.insert(k.to_owned(), from_yaml_value(uri, value)?),
other => Err(Box::new(UnsupportedHashKeyError(format!("{other:?}"))))?,
};
}
24 changes: 24 additions & 0 deletions tests/testsuite/file_yaml.rs
Original file line number Diff line number Diff line change
@@ -382,3 +382,27 @@ inner_bool:
assert_eq!(config.inner_bool.get(&true).unwrap(), "bool true");
assert_eq!(config.inner_bool.get(&false).unwrap(), "bool false");
}

#[test]
fn test_yaml_parsing_float_hash() {
#[derive(Debug, Deserialize)]
struct TestStruct {
inner_float: HashMap<String, String>,
}

let config = Config::builder()
.add_source(File::from_str(
r#"
inner_float:
0.1: "float 0.1"
0.2: "float 0.2"
"#,
FileFormat::Yaml,
))
.build()
.unwrap()
.try_deserialize::<TestStruct>()
.unwrap();
assert_eq!(config.inner_float.get("0.1").unwrap(), "float 0.1");
assert_eq!(config.inner_float.get("0.2").unwrap(), "float 0.2");
}