img-gen-spec 0.2.1

An API to create image generator specifications
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
mod validators;

use serde::de::DeserializeOwned;

/// Parse YAML with duplicate-key policy `LastWins` into type `T` by first
/// parsing into `serde_json::Value` (honors LastWins) then converting to `T`.
/// Returns a `String` error on failure for easy mapping to Python exceptions.
pub fn parse_yaml_last_wins<T>(s: &str) -> Result<T, String>
where
    T: DeserializeOwned,
{
    let opts = serde_saphyr::options! {
        duplicate_keys: serde_saphyr::options::DuplicateKeyPolicy::LastWins,
    };
    let value: serde_json::Value =
        serde_saphyr::from_str_with_options(s, opts).map_err(|e| e.to_string())?;
    serde_json::from_value(value).map_err(|e| e.to_string())
}