Crates.io | bende |
lib.rs | bende |
version | 0.5.4 |
source | src |
created_at | 2022-04-20 10:57:57.44479 |
updated_at | 2022-05-05 10:56:59.989467 |
description | A bencode encoding/decoding implementation backed by serde. |
homepage | https://github.com/Rickz75/bende |
repository | https://github.com/Rickz75/bende |
max_upload_size | |
id | 570915 |
size | 78,923 |
A rust bencode encoding/decoding implementation backed by serde.
This is one of a few bencode implementations available for rust. Though there are alternatives (see below), implementing bencode is both fun and a good learning experience. It also never hurts to have one more alternative.
There are more, but some are no longer maintained.
Add the library as a dependency to Cargo.toml
[dependencies]
bende = "0.5.4"
serde = { version = "1", features = ["derive"] }
use serde::{Deserialize, Serialize};
#[derive(Debug, PartialEq, Serialize, Deserialize)]
struct Person {
name: String,
age: u8,
is_employed: bool,
}
let jerry = Person {
name: "Jerry Smith".to_string(),
age: 50,
is_employed: false,
};
let bytes = bende::encode(&jerry).unwrap();
assert_eq!(bende::decode::<Person>(&bytes).unwrap(), jerry);
The types that are not supported are:
f32
f64
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
git checkout -b feature/AmazingFeature
)git commit -m 'Add some AmazingFeature'
)git push origin feature/AmazingFeature
)Option<_>
(Some and None) are supported by the decoder, but the encoder only supports Some
.&[u8]
or Vec<u8>
then use this crate.