5 releases

0.2.0 Feb 8, 2023
0.1.3 Sep 8, 2022
0.1.2 Jul 5, 2022
0.1.1 Jul 5, 2022
0.1.0 Jul 5, 2022

#1637 in Parser implementations

24 downloads per month

MIT/Apache

370KB
371 lines

nom_bencode

Version Downloads License Rust Docs

A bencode parser written with nom.

use nom_bencode::Value;

let data = nom_bencode::parse(b"d3:cow3:moo4:spam4:eggse").unwrap();
let v = data.first().unwrap();

if let Value::Dictionary(dict) = v {
    let v = dict.get("cow".as_bytes()).unwrap();

    if let Value::Bytes(data) = v {
        assert_eq!(data, b"moo");
    }

    let v = dict.get("spam".as_bytes()).unwrap();
    if let Value::Bytes(data) = v {
        assert_eq!(data, b"eggs");
    }
}

License: MIT OR Apache-2.0


lib.rs:

Version Downloads License Rust Docs

A bencode parser written with nom.

use nom_bencode::Value;

let data = nom_bencode::parse(b"d3:cow3:moo4:spam4:eggse").unwrap();
let v = data.first().unwrap();

if let Value::Dictionary(dict) = v {
    let v = dict.get("cow".as_bytes()).unwrap();

    if let Value::Bytes(data) = v {
        assert_eq!(data, b"moo");
    }

    let v = dict.get("spam".as_bytes()).unwrap();
    if let Value::Bytes(data) = v {
        assert_eq!(data, b"eggs");
    }
}

Dependencies

~1.2–2MB
~39K SLoC