Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] Parameterize decode and encode related structs and traits with StateTracker #47

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/decode_torrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//! ```

use bendy::{
decoding::{Error, FromBencode, Object, ResultExt},
decoding::{Error, FromBencode, ResultExt, StrictObject},
encoding::AsString,
};

Expand Down Expand Up @@ -80,7 +80,7 @@ impl FromBencode for MetaInfo {
/// non-optional and optional fields. Missing optional fields are ignored
/// but any other missing fields result in stopping the decoding and in
/// spawning [`DecodingError::MissingField`].
fn decode_bencode_object(object: Object) -> Result<Self, Error>
fn decode_bencode_object(object: StrictObject) -> Result<Self, Error>
where
Self: Sized,
{
Expand Down Expand Up @@ -146,7 +146,7 @@ impl FromBencode for Info {
/// On success the dictionary is parsed for the fields of info which are
/// necessary for torrent. Any missing field will result in a missing field
/// error which will stop the decoding.
fn decode_bencode_object(object: Object) -> Result<Self, Error>
fn decode_bencode_object(object: StrictObject) -> Result<Self, Error>
where
Self: Sized,
{
Expand Down
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
unstable_features = true

required_version = "1.4.11"
required_version = "1.4.21"
edition = "2018"

format_code_in_doc_comments = true
Expand Down
19 changes: 11 additions & 8 deletions src/decoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! For any decoding process, first we need to create a decoder:
//!
//! ```
//! # use bendy::decoding::{Decoder};
//! # use bendy::decoding::StrictDecoder as Decoder;
//! #
//! # let buf: &[u8] = b"d3:fooi1ee";
//! let _decoder = Decoder::new(buf);
Expand All @@ -16,7 +16,7 @@
//! attacker can cause your program to use, so we recommend setting the bounds tightly:
//!
//! ```
//! # use bendy::decoding::{Decoder};
//! # use bendy::decoding::StrictDecoder as Decoder;
//! #
//! # let buf: &[u8] = b"d3:fooi1ee";
//! let _decoder = Decoder::new(buf).with_max_depth(3);
Expand All @@ -28,10 +28,10 @@
//! Now, you can start reading objects:
//!
//! ```
//! # use bendy::decoding::{Decoder,Object};
//! # use bendy::decoding::{StrictDecoder as Decoder, StrictObject as Object};
//! #
//! # fn decode_list(_: bendy::decoding::ListDecoder) {}
//! # fn decode_dict(_: bendy::decoding::DictDecoder) {}
//! # fn decode_list(_: bendy::decoding::StrictListDecoder) {}
//! # fn decode_dict(_: bendy::decoding::StrictDictDecoder) {}
//! #
//! # let buf: &[u8] = b"d3:fooi1ee";
//! # let mut decoder = Decoder::new(buf);
Expand All @@ -52,7 +52,7 @@
//! of an input object without fully decoding it:
//!
//! ```
//! # use bendy::decoding::Decoder;
//! # use bendy::decoding::StrictDecoder as Decoder;
//! #
//! fn syntax_check(buf: &[u8]) -> bool {
//! let mut decoder = Decoder::new(buf);
Expand All @@ -69,8 +69,11 @@ mod from_bencode;
mod object;

pub use self::{
decoder::{Decoder, DictDecoder, ListDecoder, Tokens},
decoder::{
Decoder, DictDecoder, ListDecoder, StrictDecoder, StrictDictDecoder, StrictListDecoder,
Tokens,
},
error::{Error, ErrorKind, ResultExt},
from_bencode::FromBencode,
object::Object,
object::{Object, StrictObject},
};
Loading