pub fn parse<T>(stream: &mut T) -> Result<BNode>where
T: Iterator<Item = u8>,
Examples found in repository?
examples/de/main.rs (line 3)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
fn main() {
let b = "d3:inti233e3:lstl7:bencodeee";
let node = bencodex::parse(&mut b.bytes()).unwrap();
let dict = node.as_dict().unwrap();
let int = dict.get("int").unwrap().as_integer().unwrap();
assert_eq!(int, &233);
let list = dict.get("lst").unwrap().as_list().unwrap();
assert_eq!(list.len(), 1);
assert_eq!(
list.get(0).unwrap().as_bytes().unwrap(),
"bencode".as_bytes()
);
}
More examples
examples/bufreader/main.rs (line 35)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
fn main() {
let f = File::open(
env::current_dir()
.unwrap()
.join("examples")
.join("bufreader")
.join("bufreader-test.torrent"),
)
.unwrap();
let reader = BufReader::new(f);
let mut adapter = Adapter {
bytes: reader.bytes(),
};
let bnode = bencodex::parse(&mut adapter).unwrap();
let dict = bnode.as_dict().unwrap();
assert_eq!(
dict.get("bar").unwrap().as_bytes().unwrap(),
"spam".as_bytes()
);
assert_eq!(dict.get("foo").unwrap().as_integer().unwrap(), &42);
}