-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathext.rs
More file actions
34 lines (29 loc) · 833 Bytes
/
ext.rs
File metadata and controls
34 lines (29 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use crate::{Header, HeaderValue};
/// An external trait adding helper methods to types which implement [`Header`] trait.
pub trait HeaderExt: Header + self::sealed::Sealed {
/// Encode this [`Header`] to [`HeaderValue`].
fn encode_to_value(&self) -> HeaderValue;
}
impl<H> HeaderExt for H
where
H: Header + self::sealed::Sealed,
{
fn encode_to_value(&self) -> HeaderValue {
let mut container = Vec::with_capacity(1);
self.encode(&mut container);
container.remove(0)
}
}
mod sealed {
pub trait Sealed {}
impl<H: crate::Header> Sealed for H {}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn encode_header() {
let header_value = crate::AcceptRanges::bytes().encode_to_value();
assert_eq!(header_value, HeaderValue::from_static("bytes"));
}
}