conjure_http/
path_params.rs1use std::collections::hash_map::{self, HashMap};
18use std::ops::Index;
19
20#[derive(Clone, Debug, Default, PartialEq, Eq)]
22pub struct PathParams(HashMap<String, String>);
23
24impl PathParams {
25 #[inline]
27 pub fn new() -> PathParams {
28 PathParams::default()
29 }
30
31 #[inline]
33 pub fn insert<T, U>(&mut self, key: T, value: U)
34 where
35 T: Into<String>,
36 U: Into<String>,
37 {
38 self.0.insert(key.into(), value.into());
39 }
40
41 #[inline]
43 pub fn iter(&self) -> Iter<'_> {
44 Iter(self.0.iter())
45 }
46}
47
48impl<'a> IntoIterator for &'a PathParams {
49 type IntoIter = Iter<'a>;
50 type Item = (&'a str, &'a str);
51
52 #[inline]
53 fn into_iter(self) -> Iter<'a> {
54 self.iter()
55 }
56}
57
58impl<'a> Index<&'a str> for PathParams {
59 type Output = str;
60
61 #[inline]
62 fn index(&self, key: &'a str) -> &str {
63 &self.0[key]
64 }
65}
66
67pub struct Iter<'a>(hash_map::Iter<'a, String, String>);
69
70impl<'a> Iterator for Iter<'a> {
71 type Item = (&'a str, &'a str);
72
73 #[inline]
74 fn next(&mut self) -> Option<(&'a str, &'a str)> {
75 self.0.next().map(|v| (&**v.0, &**v.1))
76 }
77
78 #[inline]
79 fn size_hint(&self) -> (usize, Option<usize>) {
80 self.0.size_hint()
81 }
82}
83
84impl ExactSizeIterator for Iter<'_> {
85 #[inline]
86 fn len(&self) -> usize {
87 self.0.len()
88 }
89}