2 unstable releases

0.2.0 Nov 5, 2023
0.1.0 Aug 8, 2021

#1351 in Parser implementations

Download history 730/week @ 2024-08-19 848/week @ 2024-08-26 1089/week @ 2024-09-02 815/week @ 2024-09-09 510/week @ 2024-09-16 595/week @ 2024-09-23 713/week @ 2024-09-30 951/week @ 2024-10-07 1115/week @ 2024-10-14 829/week @ 2024-10-21 905/week @ 2024-10-28 1105/week @ 2024-11-04 861/week @ 2024-11-11 932/week @ 2024-11-18 892/week @ 2024-11-25 867/week @ 2024-12-02

3,719 downloads per month
Used in 33 crates (6 directly)

MIT/Apache

34KB
525 lines

keyvalues-parser

codecov build status Documentation

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.

Installation

Just add the library to your Cargo.toml

[dependencies]
keyvalues-parser = "0.1.0"

Quickstart

const LOGIN_USERS_VDF: &str = r#"
"users"
{
    "12345678901234567"
    {
        "AccountName"        "ACCOUNT_NAME"
        "PersonaName"        "PERSONA_NAME"
        "RememberPassword"    "1"
        "MostRecent"        "1"
        "Timestamp"        "1234567890"
    }
}
"#;

use keyvalues_parser::Vdf;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let vdf = Vdf::parse(LOGIN_USERS_VDF)?;
    assert_eq!(
        "12345678901234567",
	vdf.value.unwrap_obj().keys().next().unwrap(),
    );

    Ok(())
}

Limitations

VDF text is drastically underspecified. This leads to the following liberties being taken

  • Not respecting the ordering of key-value pairs, where the pairs are stored in a BTreeMap that sorts the values based on the key
  • Because of limitations in representing sequences, an empty Vec of values will be rendered as a missing keyvalue pair

Benchmarks

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

License

Licensed under either of

at your option.

Contribution

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.

Dependencies

~2–2.8MB
~57K SLoC