Skip to content

Commit 338508d

Browse files
committed
Implement Header for (&str, &str)
1 parent 463f3c2 commit 338508d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/headers/header.rs

+23
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,26 @@ pub trait Header {
1616
headers.as_mut().insert(name, value);
1717
}
1818
}
19+
20+
impl<'a, 'b> Header for (&'a str, &'b str) {
21+
fn header_name(&self) -> HeaderName {
22+
HeaderName::from(self.0)
23+
}
24+
25+
fn header_value(&self) -> HeaderValue {
26+
HeaderValue::from_bytes(self.1.to_owned().into_bytes())
27+
.expect("String slice should be valid ASCII")
28+
}
29+
}
30+
31+
#[cfg(test)]
32+
mod test {
33+
use super::*;
34+
35+
#[test]
36+
fn header_from_strings() {
37+
let strings = ("Content-Length", "12");
38+
assert_eq!(strings.header_name(), "Content-Length");
39+
assert_eq!(strings.header_value(), "12");
40+
}
41+
}

0 commit comments

Comments
 (0)