use serde::Deserialize;
#[derive(Debug, Deserialize)]
#[allow(dead_code)]
struct Config {
server: Server,
}
#[derive(Debug, Deserialize)]
#[allow(dead_code)]
struct Server {
host: String,
port: u16,
}
fn main() {
let yaml = r#"
server:
host: localhost
port: "oops"
"#;
let res: Result<Config, serde_saphyr::Error> = serde_saphyr::with_deserializer_from_str(
yaml,
|de| match serde_path_to_error::deserialize::<_, Config>(de) {
Ok(v) => Ok(v),
Err(e) => Err(<serde_saphyr::Error as serde::de::Error>::custom(format!(
"deserialization error at {}: {}",
e.path(),
e
))),
},
);
match res {
Ok(cfg) => println!("Parsed config: {cfg:?}"),
Err(e) => eprintln!("{e}"),
}
}