serde_bencode/lib.rs
1//! This crate is a Rust library for using the [Serde](https://github.com/serde-rs/serde)
2//! serialization framework with bencode data.
3//!
4//! # Examples
5//!
6//! ```
7//! use serde_derive::{Serialize, Deserialize};
8//!
9//! #[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
10//! struct Product {
11//! name: String,
12//! price: u32,
13//! }
14//!
15//! fn main() -> Result<(), Box<dyn std::error::Error>> {
16//! let apple = Product {
17//! name: "Apple".to_string(),
18//! price: 130,
19//! };
20//!
21//! let serialized = serde_bencode::to_string(&apple)?;
22//!
23//! // cspell:disable-next-line
24//! assert_eq!(serialized, "d4:name5:Apple5:pricei130ee".to_string());
25//!
26//! let deserialized: Product = serde_bencode::from_str(&serialized)?;
27//!
28//! assert_eq!(
29//! deserialized,
30//! Product {
31//! name: "Apple".to_string(),
32//! price: 130,
33//! }
34//! );
35//!
36//! Ok(())
37//! }
38//! ```
39
40pub mod de;
41pub mod error;
42pub mod ser;
43pub mod value;
44
45pub use de::{from_bytes, from_str, Deserializer};
46pub use error::{Error, Result};
47pub use ser::{to_bytes, to_string, Serializer};