Skip to content

Commit

Permalink
fix(header): deprecate HeaderFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Jan 30, 2017
1 parent 7611c30 commit 282466e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ license = "MIT"
authors = ["Sean McArthur <[email protected]>",
"Jonathan Reem <[email protected]>"]
keywords = ["http", "hyper", "hyperium"]
build = "build.rs"

[dependencies]
httparse = "1.0"
Expand All @@ -28,5 +29,8 @@ url = "1.0"
[dev-dependencies]
env_logger = "0.3"

[build-dependencies]
rustc_version = "0.1"

[features]
nightly = []
7 changes: 7 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extern crate rustc_version as rustc;

fn main() {
if rustc::version_matches(">= 1.9") {
println!("cargo:rustc-cfg=has_deprecated");
}
}
20 changes: 14 additions & 6 deletions src/header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,11 +495,14 @@ impl<'a> FromIterator<HeaderView<'a>> for Headers {
}
}

impl<'a> fmt::Display for &'a (HeaderFormat + Send + Sync) {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut multi = MultilineFormatter(Multi::Join(true, f));
self.fmt_multi_header(&mut multi)
deprecated! {
#[deprecated(note="The semantics of formatting a HeaderFormat directly are not clear")]
impl<'a> fmt::Display for &'a (HeaderFormat + Send + Sync) {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut multi = MultilineFormatter(Multi::Join(true, f));
self.fmt_multi_header(&mut multi)
}
}
}

Expand All @@ -510,8 +513,12 @@ impl<'a> fmt::Display for &'a (HeaderFormat + Send + Sync) {
///
/// Note: This may not necessarily be the value written to stream, such
/// as with the SetCookie header.
pub struct HeaderFormatter<'a, H: HeaderFormat>(pub &'a H);
deprecated! {
#[deprecated(note="The semantics of formatting a HeaderFormat directly are not clear")]
pub struct HeaderFormatter<'a, H: HeaderFormat>(pub &'a H);
}

#[allow(deprecated)]
impl<'a, H: HeaderFormat> fmt::Display for HeaderFormatter<'a, H> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand All @@ -520,6 +527,7 @@ impl<'a, H: HeaderFormat> fmt::Display for HeaderFormatter<'a, H> {
}
}

#[allow(deprecated)]
impl<'a, H: HeaderFormat> fmt::Debug for HeaderFormatter<'a, H> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ macro_rules! inspect(
})
);

macro_rules! deprecated {
(#[$note:meta] $i:item) => (
#[cfg_attr(has_deprecated, $note)]
$i
);
}

#[cfg(test)]
#[macro_use]
mod mock;
Expand Down

0 comments on commit 282466e

Please sign in to comment.