| Crates.io | keyvalues-parser |
| lib.rs | keyvalues-parser |
| version | 0.2.3 |
| created_at | 2021-08-08 21:40:52.218954+00 |
| updated_at | 2026-01-05 10:23:56.89087+00 |
| description | A parser/renderer for vdf text |
| homepage | https://codeberg.org/CosmicHarper/vdf-rs/src/branch/main/keyvalues-parser |
| repository | https://codeberg.org/CosmicHarper/vdf-rs |
| max_upload_size | |
| id | 433353 |
| size | 90,039 |
keyvalues-parser uses pest to parse
VDF text v1
files to an untyped Rust structure to ease manipulation and navigation. The
parser provides an untyped Vdf representation as well as a linear
TokenStream
The library is primarily used in conjunction with
keyvalues-serde which provides a
more ergonomic (yet more limiting) means of dealing with VDF text.
Just add the library to your Cargo.toml
$ cargo add keyvalues-parser
const LOGIN_USERS_VDF: &str = r#"
"users"
{
"12345678901234567"
{
"AccountName" "ACCOUNT_NAME"
"PersonaName" "PERSONA_NAME"
"RememberPassword" "1"
"MostRecent" "1"
"Timestamp" "1234567890"
}
}
"#;
fn main() -> keyvalues_parser::error::Result<()> {
let vdf = keyvalues_parser::parse(LOGIN_USERS_VDF)?;
assert_eq!(
"12345678901234567",
vdf.value.unwrap_obj().keys().next().unwrap(),
);
Ok(())
}
VDF text is drastically underspecified. This leads to the following liberties being taken
BTreeMap that sorts the values based on the keyVec of values will be rendered as a missing keyvalue pairserde supportDeserialize is implemented for a handful of traits with the caveat that
sequences can be problematic when going through the self-describing serde
API's. This is most commonly encountered when trying to serde(flatten) to
something like an Obj where it will fail deserializing any field that's not
a sequence (so most of them...).
A set of basic benchmarks can be found in the benches directory
These just test timing and throughput for both parsing and rendering of a fairly typical VDF file
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.