containers_api/conn/
headers.rs

1#[derive(Debug, Default, Clone)]
2/// Helper structure used as a container for HTTP headers passed to a request
3pub struct Headers(Vec<(&'static str, String)>);
4
5impl Headers {
6    /// Shortcut for when one does not want headers in a request
7    pub fn none() -> Option<Headers> {
8        None
9    }
10
11    /// Adds a single key=value header pair
12    pub fn add<V>(&mut self, key: &'static str, val: V)
13    where
14        V: Into<String>,
15    {
16        self.0.push((key, val.into()))
17    }
18
19    /// Constructs an instance of Headers with initial pair, usually used when there is only
20    /// a need for one header.
21    pub fn single<V>(key: &'static str, val: V) -> Self
22    where
23        V: Into<String>,
24    {
25        let mut h = Self::default();
26        h.add(key, val);
27        h
28    }
29}
30
31impl IntoIterator for Headers {
32    type Item = (&'static str, String);
33    type IntoIter = std::vec::IntoIter<Self::Item>;
34
35    fn into_iter(self) -> Self::IntoIter {
36        self.0.into_iter()
37    }
38}