parse

Function parse 

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