bencode_full/
bencode_full.rs1use babbel_bencode::{
7 BufferDestination, parse_bytes, stringify_to_bytes, to_json, to_toml, to_xml, to_yaml,
8};
9
10fn main() {
11 let dict = b"d3:agei25e4:name4:Johne";
13
14 if let Ok(node) = parse_bytes(dict) {
15 if let Ok(output) = stringify_to_bytes(&node) {
17 assert_eq!(output, dict);
18 println!("Bencode: {}", String::from_utf8_lossy(&output));
19 }
20
21 let mut buffer = BufferDestination::new();
23 if to_json(&node, &mut buffer).is_ok() {
24 println!("JSON: {}", String::from_utf8_lossy(&buffer.buffer));
25 }
26
27 let mut buffer = BufferDestination::new();
28 if to_toml(&node, &mut buffer).is_ok() {
29 println!("TOML: {}", String::from_utf8_lossy(&buffer.buffer));
30 }
31
32 let mut buffer = BufferDestination::new();
33 if to_xml(&node, &mut buffer).is_ok() {
34 println!("XML: {}", String::from_utf8_lossy(&buffer.buffer));
35 }
36
37 let mut buffer = BufferDestination::new();
38 if to_yaml(&node, &mut buffer).is_ok() {
39 println!("YAML: {}", String::from_utf8_lossy(&buffer.buffer));
40 }
41 }
42}