format_serde_error 0.3.0

Serde error messages for humans.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use anyhow::anyhow;

use format_serde_error::SerdeError;

#[derive(Debug, serde::Serialize, serde::Deserialize)]
struct Config {
    values: Vec<String>,
}

fn main() -> Result<(), anyhow::Error> {
    let config_str = "values:
	- 'first'
	- 'second'
	- third:";

    let err = anyhow!("values[2]: invalid type: map, expected a string at line 4 column 8");
    Err(SerdeError::new(config_str.to_string(), (err.into(), Some(4), Some(8))).into())
}