About
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.
Alternatives
- bendy by P3KI.
- serde-bencode by Toby Padilla.
- rust-bencode by Arjan Topolovec.
There are more, but some are no longer maintained.
Usage
Add the library as a dependency to Cargo.toml
[]
= "0.5.4"
= { = "1", = ["derive"] }
Example
use ;
let jerry = Person ;
let bytes = encode.unwrap;
assert_eq!;
Unsupported Types
The types that are not supported are:
f32f64
Contributing
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!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Notes
- Both variants of
Option<_>(Some and None) are supported by the decoder, but the encoder only supportsSome. - Keys in a key-value object must be strings, otherwise an error is returned.
- Map and struct entries are sorted lexicographically by their key before they are encoded.
- If you run into trouble encoding/decoding raw bytes, eg:
&[u8]orVec<u8>then use this crate. - The codebase is relatively small (~2000 lines), easily digestible and filled with comments. If you're a first timer, you'll have a jolly time making your first contribution.