Crate nom_bencode
source · [−]Expand description
A bencode parser written with nom.
let data = parse(b"d3:cow3:moo4:spam4:eggse").unwrap();
let v = data.first().unwrap();
assert_matches!(v, Value::Dictionary(_));
if let Value::Dictionary(dict) = v {
let v = dict.get("cow".as_bytes()).unwrap();
assert_matches!(*v, Value::Bytes(b"moo"));
let v = dict.get("spam".as_bytes()).unwrap();
assert_matches!(*v, Value::Bytes(b"eggs"));
}
let (_, v) = Value::parse_dict(b"d4:spaml1:a1:bee").unwrap();
assert_matches!(v, Value::Dictionary(_));
if let Value::Dictionary(dict) = v {
let v = dict.get("spam".as_bytes()).unwrap();
assert_matches!(*v, Value::List(_));
}