Skip to content

Commit 13e8791

Browse files
committed
docs fixes
1 parent 672ffcf commit 13e8791

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,13 @@ impl From<std::convert::Infallible> for Error {
137137
}
138138
}
139139

140+
/// Error returned when max capacity of `HeaderMap` is exceeded
140141
pub struct CapacityOverflow {
141142
_priv: (),
142143
}
143144

144145
impl CapacityOverflow {
146+
/// Create new `CapacityOverflow` instance
145147
pub fn new() -> CapacityOverflow {
146148
CapacityOverflow { _priv: () }
147149
}

src/header/map.rs

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,12 +1081,31 @@ impl<T> HeaderMap<T> {
10811081
/// Gets the given key's corresponding entry in the map for in-place
10821082
/// manipulation.
10831083
///
1084-
/// # Errors
1084+
/// # Panics
10851085
///
1086-
/// This method differs from `entry` by allowing types that may not be
1087-
/// valid `HeaderName`s to passed as the key (such as `String`). If they
1088-
/// do not parse as a valid `HeaderName`, this returns an
1089-
/// `InvalidHeaderName` error.
1086+
/// This method panics if capacity exceeds max `HeaderMap` capacity
1087+
///
1088+
/// # Examples
1089+
///
1090+
/// ```
1091+
/// # use http::HeaderMap;
1092+
/// let mut map: HeaderMap<u32> = HeaderMap::default();
1093+
///
1094+
/// let headers = &[
1095+
/// "content-length",
1096+
/// "x-hello",
1097+
/// "Content-Length",
1098+
/// "x-world",
1099+
/// ];
1100+
///
1101+
/// for &header in headers {
1102+
/// let counter = map.entry(header).or_insert(0);
1103+
/// *counter += 1;
1104+
/// }
1105+
///
1106+
/// assert_eq!(map["content-length"], 2);
1107+
/// assert_eq!(map["x-hello"], 1);
1108+
/// ```
10901109
pub fn entry<K>(&mut self, key: K) -> Entry<'_, T>
10911110
where
10921111
K: IntoHeaderName,
@@ -1103,6 +1122,9 @@ impl<T> HeaderMap<T> {
11031122
/// valid `HeaderName`s to passed as the key (such as `String`). If they
11041123
/// do not parse as a valid `HeaderName`, this returns an
11051124
/// `InvalidHeaderName` error.
1125+
///
1126+
/// It may return `CapacityOverflow` error if size exceeds the maximum
1127+
/// `HeaderMap` capacity
11061128
pub fn try_entry<K>(&mut self, key: K) -> Result<Entry<'_, T>, Error>
11071129
where
11081130
K: AsHeaderName,
@@ -1162,16 +1184,20 @@ impl<T> HeaderMap<T> {
11621184
/// The key is not updated, though; this matters for types that can be `==`
11631185
/// without being identical.
11641186
///
1187+
/// # Panics
1188+
///
1189+
/// This method panics if capacity exceeds max `HeaderMap` capacity
1190+
///
11651191
/// # Examples
11661192
///
11671193
/// ```
11681194
/// # use http::HeaderMap;
11691195
/// # use http::header::HOST;
11701196
/// let mut map = HeaderMap::new();
1171-
/// assert!(map.try_insert(HOST, "world".parse().unwrap()).unwrap().is_none());
1197+
/// assert!(map.insert(HOST, "world".parse().unwrap()).is_none());
11721198
/// assert!(!map.is_empty());
11731199
///
1174-
/// let mut prev = map.try_insert(HOST, "earth".parse().unwrap()).unwrap().unwrap();
1200+
/// let mut prev = map.insert(HOST, "earth".parse().unwrap()).unwrap();
11751201
/// assert_eq!("world", prev);
11761202
/// ```
11771203
pub fn insert<K>(&mut self, key: K, val: T) -> Option<T>
@@ -1295,16 +1321,20 @@ impl<T> HeaderMap<T> {
12951321
/// updated, though; this matters for types that can be `==` without being
12961322
/// identical.
12971323
///
1324+
/// # Panics
1325+
///
1326+
/// This method panics if capacity exceeds max `HeaderMap` capacity
1327+
///
12981328
/// # Examples
12991329
///
13001330
/// ```
13011331
/// # use http::HeaderMap;
13021332
/// # use http::header::HOST;
13031333
/// let mut map = HeaderMap::new();
1304-
/// assert!(map.try_insert(HOST, "world".parse().unwrap()).unwrap().is_none());
1334+
/// assert!(map.insert(HOST, "world".parse().unwrap()).is_none());
13051335
/// assert!(!map.is_empty());
13061336
///
1307-
/// map.try_append(HOST, "earth".parse().unwrap()).unwrap();
1337+
/// map.append(HOST, "earth".parse().unwrap());
13081338
///
13091339
/// let values = map.get_all("host");
13101340
/// let mut i = values.iter();

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
//! assert_eq!(uri.query(), None);
159159
//! ```
160160
161-
#![deny(warnings, missing_debug_implementations)]
161+
#![deny(warnings, missing_docs, missing_debug_implementations)]
162162

163163
#[cfg(test)]
164164
#[macro_use]

0 commit comments

Comments
 (0)