Skip to content

Commit 291527b

Browse files
committed
Add headers::HeaderValues
1 parent 42c70ac commit 291527b

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/headers/header_values.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use crate::headers::HeaderValue;
2+
use std::fmt::{self, Display};
3+
4+
/// A list of `HeaderValue`s.
5+
///
6+
/// This always contains at least one header value.
7+
#[derive(Debug)]
8+
pub struct HeaderValues {
9+
inner: Vec<HeaderValue>,
10+
}
11+
12+
impl Display for HeaderValues {
13+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14+
let mut list = f.debug_list();
15+
for v in &self.inner {
16+
list.entry(&v);
17+
}
18+
list.finish()
19+
}
20+
}
21+
22+
impl PartialEq<str> for HeaderValues {
23+
fn eq(&self, other: &str) -> bool {
24+
self.inner[0] == other
25+
}
26+
}
27+
28+
impl<'a> PartialEq<&'a str> for HeaderValues {
29+
fn eq(&self, other: &&'a str) -> bool {
30+
&self.inner[0] == other
31+
}
32+
}
33+
34+
impl PartialEq<String> for HeaderValues {
35+
fn eq(&self, other: &String) -> bool {
36+
&self.inner[0] == other
37+
}
38+
}
39+
40+
impl<'a> PartialEq<&String> for HeaderValues {
41+
fn eq(&self, other: &&String) -> bool {
42+
&&self.inner[0] == other
43+
}
44+
}

src/headers/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::iter::IntoIterator;
77
mod constants;
88
mod header_name;
99
mod header_value;
10+
mod header_values;
1011
mod into_iter;
1112
mod iter;
1213
mod iter_mut;
@@ -17,6 +18,7 @@ mod values;
1718
pub use constants::*;
1819
pub use header_name::HeaderName;
1920
pub use header_value::HeaderValue;
21+
pub use header_values::HeaderValues;
2022
pub use into_iter::IntoIter;
2123
pub use iter::Iter;
2224
pub use iter_mut::IterMut;

0 commit comments

Comments
 (0)