[−][src]Crate serde_bencode
This crate is a Rust library for using the Serde serialization framework with bencode data.
Examples
use serde_derive::{Serialize, Deserialize}; #[derive(Serialize, Deserialize, PartialEq, Eq, Debug)] struct Product { name: String, price: u32, } fn main() -> Result<(), Box<dyn std::error::Error>> { let apple = Product { name: "Apple".to_string(), price: 130, }; let serialized = serde_bencode::to_string(&apple)?; assert_eq!(serialized, "d4:name5:Apple5:pricei130ee".to_string()); let deserialized: Product = serde_bencode::from_str(&serialized)?; assert_eq!( deserialized, Product { name: "Apple".to_string(), price: 130, } ); Ok(()) }
Re-exports
pub use error::Error; |
pub use error::Result; |
pub use ser::to_bytes; |
pub use ser::to_string; |
pub use ser::Serializer; |
pub use de::from_str; |
pub use de::from_bytes; |
pub use de::Deserializer; |
Modules
de | Deserialize bencode data to a Rust data structure |
error | Structures used to handle errors when serializing or deserializing goes wrong. |
ser | Serialize a Rust data structure into bencode data. |
value | Structures for representing bencoded values with Rust data types. |