1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//! Returns the `serde_yaml` error location and message to pass to `miette`.
//!
//! # Examples
//!
//! ```rust
//! use serde::{Deserialize, Serialize};
//! use yaml_error_context_hack::{ErrorAndContext, SourceOffset};
//!
//! #[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)]
//! struct Config {
//! outer: Outer,
//! }
//!
//! #[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)]
//! struct Outer {
//! field_1: u32,
//! field_2: u32,
//! }
//!
//! let file_contents = r#"---
//! outer:
//! field_1: 123
//! ## ^
//! ## '--- field_2 missing the first character of the first type that has `#[serde(flatten)]`.
//! "#;
//! let error = serde_yaml::from_str::<Config>(&file_contents).unwrap_err();
//! let error_and_context = ErrorAndContext::new(file_contents, &error);
//!
//! let loc_line = 3;
//! let loc_col = 3; // index 2 is column 3
//!
//! assert_eq!(
//! "outer: missing field `field_2` at line 3 column 3",
//! error.to_string()
//! );
//! assert_eq!(
//! ErrorAndContext {
//! error_span: Some(SourceOffset::from_location(
//! file_contents,
//! loc_line,
//! loc_col
//! )),
//! error_message: "outer: missing field `field_2`".to_string(),
//! context_span: None,
//! },
//! error_and_context,
//! "{error}"
//! );
//! ```
// Re-exports
pub use ;
pub use crateErrorAndContext;