|
1 | 1 | # `kdl`
|
2 | 2 |
|
3 |
| -`kdl` is a "document-oriented" parser and API. That means that, unlike |
4 |
| -serde-based implementations, it's meant to preserve formatting when |
5 |
| -editing, as well as inserting values with custom formatting. This is |
6 |
| -useful when working with human-maintained KDL files. |
| 3 | +`kdl` is a "document-oriented" parser and API for the [KDL Document |
| 4 | +Language](https://kdl.dev), a node-based, human-friendly configuration and |
| 5 | +serialization format. Unlike serde-based implementations, this crate |
| 6 | +preserves formatting when editing, as well as when inserting or changing |
| 7 | +values with custom formatting. This is most useful when working with |
| 8 | +human-maintained KDL files. |
7 | 9 |
|
8 | 10 | You can think of this crate as
|
9 | 11 | [`toml_edit`](https://crates.io/crates/toml_edit), but for KDL.
|
10 | 12 |
|
| 13 | +If you don't care about formatting or programmatic manipulation, you might |
| 14 | +check out [`knuffel`](https://crates.io/crates/knuffel) or |
| 15 | +[`kaydle`](https://crates.io/crates/kaydle) instead for serde (or |
| 16 | +serde-like) parsing. |
| 17 | + |
11 | 18 | ### Example
|
12 | 19 |
|
13 | 20 | ```rust
|
@@ -59,6 +66,29 @@ assert_eq!(&doc.to_string(), node_str);
|
59 | 66 | [`KdlDocument`], [`KdlNode`], [`KdlEntry`], and [`KdlIdentifier`] can all
|
60 | 67 | be parsed and managed this way.
|
61 | 68 |
|
| 69 | + |
| 70 | +This error implements [`miette::Diagnostic`] and can be used to display |
| 71 | +detailed, pretty-printed diagnostic messages when using [`miette::Result`] |
| 72 | +and the `"pretty"` feature flag for `miette`: |
| 73 | + |
| 74 | +```rust |
| 75 | +fn main() -> miette::Result<()> { |
| 76 | + "foo 1.".parse::<kdl::KdlDocument>()?; |
| 77 | + Ok(()) |
| 78 | +} |
| 79 | +``` |
| 80 | + |
| 81 | +This will display a message like: |
| 82 | +``` |
| 83 | +Error: |
| 84 | + × Expected valid value. |
| 85 | + ╭──── |
| 86 | + 1 │ foo 1. |
| 87 | + · ─┬ |
| 88 | + · ╰── invalid float |
| 89 | + ╰──── |
| 90 | + help: Floating point numbers must be base 10, and have numbers after the decimal point. |
| 91 | +``` |
62 | 92 | ### License
|
63 | 93 |
|
64 | 94 | The code in this repository is covered by [the Apache-2.0
|
|
0 commit comments