Skip to content

Commit

Permalink
use built in forward_to_deserialize
Browse files Browse the repository at this point in the history
  • Loading branch information
toby committed Dec 21, 2016
1 parent 9837869 commit d3273b4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "serde_bencode"
description = "A Serde backed Bencode encoding/decoding library for Rust."
version = "0.1.0"
version = "0.1.1"
authors = ["Toby Padilla <[email protected]>"]
repository = "https://github.com/toby/serde-bencode"
license = "MIT"
Expand Down
42 changes: 5 additions & 37 deletions src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@ use serde::de::{Deserializer, Deserialize, Visitor, VariantVisitor, SeqVisitor,
EnumVisitor, Error};
use error::BencodeError;

macro_rules! forward_deserialize {
($($name:ident($($arg:ident: $ty:ty,)*);)*) => {
$(#[inline]
fn $name<V: Visitor>(&mut self, $($arg: $ty,)* visitor: V) -> Result<V::Value> {
self.deserialize(visitor)
})*
}
}

pub type Result<T> = result::Result<T, BencodeError>;

pub struct BencodeVisitor<'a, R: 'a + Read> {
Expand Down Expand Up @@ -239,34 +230,11 @@ impl<R: Read> Deserializer for BencodeDecoder<R> {
}
}

forward_deserialize!(
deserialize_i64();
deserialize_string();
deserialize_seq();
deserialize_seq_fixed_size(_len: usize,);
deserialize_bool();
deserialize_isize();
deserialize_i8();
deserialize_i16();
deserialize_i32();
deserialize_usize();
deserialize_u8();
deserialize_u16();
deserialize_u32();
deserialize_u64();
deserialize_f32();
deserialize_f64();
deserialize_char();
deserialize_str();
deserialize_unit();
deserialize_bytes();
deserialize_map();
deserialize_unit_struct(_name: &'static str,);
deserialize_tuple_struct(_name: &'static str, _len: usize,);
deserialize_tuple(_len: usize,);
deserialize_newtype_struct(_name: &'static str,);
deserialize_ignored_any();
);
forward_to_deserialize! {
i64 string seq seq_fixed_size bool isize i8 i16 i32 usize u8 u16 u32
u64 f32 f64 char str unit bytes map unit_struct tuple_struct tuple
newtype_struct ignored_any
}

#[inline]
fn deserialize_option<V:Visitor>(&mut self, visitor: V) -> Result<V::Value> {
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![feature(proc_macro)]

#[macro_use]
extern crate serde;
#[macro_use]
extern crate serde_derive;
Expand Down

0 comments on commit d3273b4

Please sign in to comment.