This commit is contained in:
Edgar 2022-09-08 08:37:49 +02:00
parent b3a18332dd
commit 6408ddb6a3
No known key found for this signature in database
GPG key ID: 8731E6C0166EAA85

View file

@ -313,4 +313,26 @@ pub fn parse(source: &[u8]) -> Result<Vec<Value>, Error<&[u8]>> {
}
```
An example using the parser:
```rust
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");
}
}
```
You can find the full source code here: <https://github.com/edg-l/nom-bencode>