@@ -1081,12 +1081,31 @@ impl<T> HeaderMap<T> {
1081
1081
/// Gets the given key's corresponding entry in the map for in-place
1082
1082
/// manipulation.
1083
1083
///
1084
- /// # Errors
1084
+ /// # Panics
1085
1085
///
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
+ /// ```
1090
1109
pub fn entry < K > ( & mut self , key : K ) -> Entry < ' _ , T >
1091
1110
where
1092
1111
K : IntoHeaderName ,
@@ -1103,6 +1122,9 @@ impl<T> HeaderMap<T> {
1103
1122
/// valid `HeaderName`s to passed as the key (such as `String`). If they
1104
1123
/// do not parse as a valid `HeaderName`, this returns an
1105
1124
/// `InvalidHeaderName` error.
1125
+ ///
1126
+ /// It may return `CapacityOverflow` error if size exceeds the maximum
1127
+ /// `HeaderMap` capacity
1106
1128
pub fn try_entry < K > ( & mut self , key : K ) -> Result < Entry < ' _ , T > , Error >
1107
1129
where
1108
1130
K : AsHeaderName ,
@@ -1162,16 +1184,20 @@ impl<T> HeaderMap<T> {
1162
1184
/// The key is not updated, though; this matters for types that can be `==`
1163
1185
/// without being identical.
1164
1186
///
1187
+ /// # Panics
1188
+ ///
1189
+ /// This method panics if capacity exceeds max `HeaderMap` capacity
1190
+ ///
1165
1191
/// # Examples
1166
1192
///
1167
1193
/// ```
1168
1194
/// # use http::HeaderMap;
1169
1195
/// # use http::header::HOST;
1170
1196
/// 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());
1172
1198
/// assert!(!map.is_empty());
1173
1199
///
1174
- /// let mut prev = map.try_insert (HOST, "earth".parse().unwrap()).unwrap( ).unwrap();
1200
+ /// let mut prev = map.insert (HOST, "earth".parse().unwrap()).unwrap();
1175
1201
/// assert_eq!("world", prev);
1176
1202
/// ```
1177
1203
pub fn insert < K > ( & mut self , key : K , val : T ) -> Option < T >
@@ -1295,16 +1321,20 @@ impl<T> HeaderMap<T> {
1295
1321
/// updated, though; this matters for types that can be `==` without being
1296
1322
/// identical.
1297
1323
///
1324
+ /// # Panics
1325
+ ///
1326
+ /// This method panics if capacity exceeds max `HeaderMap` capacity
1327
+ ///
1298
1328
/// # Examples
1299
1329
///
1300
1330
/// ```
1301
1331
/// # use http::HeaderMap;
1302
1332
/// # use http::header::HOST;
1303
1333
/// 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());
1305
1335
/// assert!(!map.is_empty());
1306
1336
///
1307
- /// map.try_append (HOST, "earth".parse().unwrap()).unwrap( );
1337
+ /// map.append (HOST, "earth".parse().unwrap());
1308
1338
///
1309
1339
/// let values = map.get_all("host");
1310
1340
/// let mut i = values.iter();
0 commit comments