Skip to content

Commit

Permalink
refactor(lib): remove serde dependency
Browse files Browse the repository at this point in the history
BREAKING CHANGE: There is no longer a `serde-serialization` feature.
  Look at external crates, like `hyper-serde`, to fulfill this feature.
  • Loading branch information
seanmonstar committed Jan 4, 2017
1 parent 2f48612 commit 7b9817e
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 114 deletions.
5 changes: 0 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,8 @@ default-features = false
version = "0.4"
default-features = false

[dependencies.serde]
version = "0.7"
optional = true

[dev-dependencies]
env_logger = "0.3"

[features]
serde-serialization = ["serde", "mime/serde"]
nightly = []
1 change: 0 additions & 1 deletion src/header/common/content_length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ impl fmt::Display for ContentLength {
}

__hyper__deref!(ContentLength => u64);
__hyper_generate_header_serialization!(ContentLength);

__hyper__tm!(ContentLength, tests {
// Testcase from RFC
Expand Down
31 changes: 0 additions & 31 deletions src/header/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,32 +178,6 @@ macro_rules! test_header {
}
}

#[doc(hidden)]
#[macro_export]
macro_rules! __hyper_generate_header_serialization {
($id:ident) => {
#[cfg(feature = "serde-serialization")]
impl ::serde::Serialize for $id {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
where S: ::serde::Serializer {
format!("{}", self).serialize(serializer)
}
}

#[cfg(feature = "serde-serialization")]
impl ::serde::Deserialize for $id {
fn deserialize<D>(deserializer: &mut D) -> Result<$id, D::Error>
where D: ::serde::Deserializer {
let string_representation: String =
try!(::serde::Deserialize::deserialize(deserializer));
Ok($crate::header::Header::parse_header(&[
string_representation.into_bytes()
]).unwrap())
}
}
}
}

#[macro_export]
macro_rules! header {
// $a:meta: Attributes associated with the header item (usually docs)
Expand Down Expand Up @@ -236,8 +210,6 @@ macro_rules! header {
self.fmt_header(f)
}
}

__hyper_generate_header_serialization!($id);
};
// List header, one or more items
($(#[$a:meta])*($id:ident, $n:expr) => ($item:ty)+) => {
Expand All @@ -264,7 +236,6 @@ macro_rules! header {
self.fmt_header(f)
}
}
__hyper_generate_header_serialization!($id);
};
// Single value header
($(#[$a:meta])*($id:ident, $n:expr) => [$value:ty]) => {
Expand All @@ -290,7 +261,6 @@ macro_rules! header {
::std::fmt::Display::fmt(&**self, f)
}
}
__hyper_generate_header_serialization!($id);
};
// List header, one or more items with "*" option
($(#[$a:meta])*($id:ident, $n:expr) => {Any / ($item:ty)+}) => {
Expand Down Expand Up @@ -331,7 +301,6 @@ macro_rules! header {
self.fmt_header(f)
}
}
__hyper_generate_header_serialization!($id);
};

// optional test module
Expand Down
41 changes: 0 additions & 41 deletions src/header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,6 @@ use unicase::UniCase;

use self::internals::{Item, VecMap, Entry};

#[cfg(feature = "serde-serialization")]
use serde::{Deserialize, Deserializer, Serialize, Serializer};
#[cfg(feature = "serde-serialization")]
use serde::de;
#[cfg(feature = "serde-serialization")]
use serde::ser;

pub use self::shared::*;
pub use self::common::*;

Expand Down Expand Up @@ -346,40 +339,6 @@ impl fmt::Debug for Headers {
}
}

#[cfg(feature = "serde-serialization")]
impl Serialize for Headers {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer {
serializer.serialize_map(ser::impls::MapIteratorVisitor::new(
self.iter().map(|header| (header.name(), header.value_string())),
Some(self.len()),
))
}
}

#[cfg(feature = "serde-serialization")]
impl Deserialize for Headers {
fn deserialize<D>(deserializer: &mut D) -> Result<Headers, D::Error> where D: Deserializer {
struct HeadersVisitor;

impl de::Visitor for HeadersVisitor {
type Value = Headers;

fn visit_map<V>(&mut self, mut visitor: V) -> Result<Headers, V::Error>
where V: de::MapVisitor {
let mut result = Headers::new();
while let Some((key, value)) = try!(visitor.visit()) {
let (key, value): (String, String) = (key, value);
result.set_raw(key, vec![value.into_bytes()]);
}
try!(visitor.end());
Ok(result)
}
}

deserializer.deserialize_map(HeadersVisitor)
}
}

/// An `Iterator` over the fields in a `Headers` map.
pub struct HeadersItems<'a> {
inner: ::std::slice::Iter<'a, (HeaderName, Item)>
Expand Down
17 changes: 0 additions & 17 deletions src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use header::Headers;
use version::HttpVersion;
use version::HttpVersion::{Http10, Http11};

#[cfg(feature = "serde-serialization")]
use serde::{Deserialize, Deserializer, Serialize, Serializer};

pub use self::message::{HttpMessage, RequestHead, ResponseHead, Protocol};

Expand All @@ -20,21 +18,6 @@ pub mod message;
#[derive(Clone, PartialEq, Debug)]
pub struct RawStatus(pub u16, pub Cow<'static, str>);

#[cfg(feature = "serde-serialization")]
impl Serialize for RawStatus {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer {
(self.0, &self.1).serialize(serializer)
}
}

#[cfg(feature = "serde-serialization")]
impl Deserialize for RawStatus {
fn deserialize<D>(deserializer: &mut D) -> Result<RawStatus, D::Error> where D: Deserializer {
let representation: (u16, String) = try!(Deserialize::deserialize(deserializer));
Ok(RawStatus(representation.0, Cow::Owned(representation.1)))
}
}

/// Checks if a connection should be kept alive.
#[inline]
pub fn should_keep_alive(version: HttpVersion, headers: &Headers) -> bool {
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@
extern crate rustc_serialize as serialize;
extern crate time;
#[macro_use] extern crate url;
#[cfg(feature = "serde-serialization")]
extern crate serde;
extern crate cookie;
extern crate unicase;
extern crate httparse;
Expand Down
17 changes: 0 additions & 17 deletions src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use error::Error;
use self::Method::{Options, Get, Post, Put, Delete, Head, Trace, Connect, Patch,
Extension};

#[cfg(feature = "serde-serialization")]
use serde::{Deserialize, Deserializer, Serialize, Serializer};

/// The Request Method (VERB)
///
Expand Down Expand Up @@ -128,21 +126,6 @@ impl fmt::Display for Method {
}
}

#[cfg(feature = "serde-serialization")]
impl Serialize for Method {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer {
format!("{}", self).serialize(serializer)
}
}

#[cfg(feature = "serde-serialization")]
impl Deserialize for Method {
fn deserialize<D>(deserializer: &mut D) -> Result<Method, D::Error> where D: Deserializer {
let string_representation: String = try!(Deserialize::deserialize(deserializer));
Ok(FromStr::from_str(&string_representation[..]).unwrap())
}
}

#[cfg(test)]
mod tests {
use std::collections::HashMap;
Expand Down

0 comments on commit 7b9817e

Please sign in to comment.