Skip to content

Commit 282466e

Browse files
committed
fix(header): deprecate HeaderFormatter
1 parent 7611c30 commit 282466e

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ license = "MIT"
1111
authors = ["Sean McArthur <[email protected]>",
1212
"Jonathan Reem <[email protected]>"]
1313
keywords = ["http", "hyper", "hyperium"]
14+
build = "build.rs"
1415

1516
[dependencies]
1617
httparse = "1.0"
@@ -28,5 +29,8 @@ url = "1.0"
2829
[dev-dependencies]
2930
env_logger = "0.3"
3031

32+
[build-dependencies]
33+
rustc_version = "0.1"
34+
3135
[features]
3236
nightly = []

build.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extern crate rustc_version as rustc;
2+
3+
fn main() {
4+
if rustc::version_matches(">= 1.9") {
5+
println!("cargo:rustc-cfg=has_deprecated");
6+
}
7+
}

src/header/mod.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -495,11 +495,14 @@ impl<'a> FromIterator<HeaderView<'a>> for Headers {
495495
}
496496
}
497497

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

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

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

530+
#[allow(deprecated)]
523531
impl<'a, H: HeaderFormat> fmt::Debug for HeaderFormatter<'a, H> {
524532
#[inline]
525533
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,13 @@ macro_rules! inspect(
172172
})
173173
);
174174

175+
macro_rules! deprecated {
176+
(#[$note:meta] $i:item) => (
177+
#[cfg_attr(has_deprecated, $note)]
178+
$i
179+
);
180+
}
181+
175182
#[cfg(test)]
176183
#[macro_use]
177184
mod mock;

0 commit comments

Comments
 (0)