1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! Minimal bencode example demonstrating smallest possible binary size
//!
//! This example shows how to use the bencode library with no default features,
//! resulting in the smallest possible binary. This is ideal for embedded systems
//! with strict size constraints.
//!
//! Features disabled:
//! - json, toml, xml, yaml format conversions
//!
//! Only core bencode parsing and stringification is available.
use babbel_bencode::{parse_bytes, stringify_to_bytes};
fn main() {
// Parse a simple bencode integer
let input = b"i42e";
match parse_bytes(input) {
Ok(node) => {
// Convert back to bencode
match stringify_to_bytes(&node) {
Ok(output) => {
assert_eq!(output, input);
println!("Parsed and stringified integer successfully");
}
Err(e) => println!("Stringify error: {}", e),
}
// No format conversions available in minimal build
// to_json, to_toml, to_xml, to_yaml are not compiled in
}
Err(e) => {
println!("Parse error: {}", e);
}
}
// Parse a bencode dictionary
let dict = b"d3:agei25e4:name4:Johne";
if let Ok(node) = parse_bytes(dict) {
if let Ok(output) = stringify_to_bytes(&node) {
assert_eq!(output, dict);
println!("Parsed and stringified dictionary successfully");
}
}
// This minimal build is perfect for:
// - Embedded systems with limited flash
// - Environments where only bencode I/O is needed
// - Applications that implement their own serialization
// - Reducing binary size by excluding unused format converters
}