@@ -7,7 +7,7 @@ use std::marker::PhantomData;
7
7
use std:: { fmt, mem, ops, ptr, vec} ;
8
8
9
9
use crate :: Error ;
10
- use crate :: error:: CapacityOverflow ;
10
+ use crate :: error:: MaxSizeReached ;
11
11
12
12
use super :: HeaderValue ;
13
13
use super :: name:: { HdrName , HeaderName } ;
@@ -489,7 +489,7 @@ impl<T> HeaderMap<T> {
489
489
/// assert!(map.is_empty());
490
490
/// assert_eq!(12, map.capacity());
491
491
/// ```
492
- pub fn try_with_capacity ( capacity : usize ) -> Result < HeaderMap < T > , CapacityOverflow > {
492
+ pub fn try_with_capacity ( capacity : usize ) -> Result < HeaderMap < T > , MaxSizeReached > {
493
493
if capacity == 0 {
494
494
Ok ( HeaderMap {
495
495
mask : 0 ,
@@ -501,7 +501,7 @@ impl<T> HeaderMap<T> {
501
501
} else {
502
502
let raw_cap = to_raw_capacity ( capacity) . next_power_of_two ( ) ;
503
503
if raw_cap > MAX_SIZE {
504
- return Err ( CapacityOverflow :: new ( ) ) ;
504
+ return Err ( MaxSizeReached :: new ( ) ) ;
505
505
}
506
506
debug_assert ! ( raw_cap > 0 ) ;
507
507
@@ -686,19 +686,19 @@ impl<T> HeaderMap<T> {
686
686
/// map.try_reserve(10).unwrap();
687
687
/// # map.try_insert(HOST, "bar".parse().unwrap()).unwrap();
688
688
/// ```
689
- pub fn try_reserve ( & mut self , additional : usize ) -> Result < ( ) , CapacityOverflow > {
689
+ pub fn try_reserve ( & mut self , additional : usize ) -> Result < ( ) , MaxSizeReached > {
690
690
// TODO: This can't overflow if done properly... since the max # of
691
691
// elements is u16::MAX.
692
692
let cap = self
693
693
. entries
694
694
. len ( )
695
695
. checked_add ( additional)
696
- . ok_or_else ( || CapacityOverflow :: new ( ) ) ?;
696
+ . ok_or_else ( || MaxSizeReached :: new ( ) ) ?;
697
697
698
698
if cap > self . indices . len ( ) {
699
- let cap = cap. checked_next_power_of_two ( ) . ok_or_else ( || CapacityOverflow :: new ( ) ) ?;
699
+ let cap = cap. checked_next_power_of_two ( ) . ok_or_else ( || MaxSizeReached :: new ( ) ) ?;
700
700
if cap > MAX_SIZE {
701
- return Err ( CapacityOverflow :: new ( ) ) ;
701
+ return Err ( MaxSizeReached :: new ( ) ) ;
702
702
}
703
703
704
704
if self . entries . len ( ) == 0 {
@@ -1123,7 +1123,7 @@ impl<T> HeaderMap<T> {
1123
1123
/// do not parse as a valid `HeaderName`, this returns an
1124
1124
/// `InvalidHeaderName` error.
1125
1125
///
1126
- /// It may return `CapacityOverflow ` error if size exceeds the maximum
1126
+ /// It may return `MaxSizeReached ` error if size exceeds the maximum
1127
1127
/// `HeaderMap` capacity
1128
1128
pub fn try_entry < K > ( & mut self , key : K ) -> Result < Entry < ' _ , T > , Error >
1129
1129
where
@@ -1132,7 +1132,7 @@ impl<T> HeaderMap<T> {
1132
1132
key. try_entry ( self )
1133
1133
}
1134
1134
1135
- fn try_entry2 < K > ( & mut self , key : K ) -> Result < Entry < ' _ , T > , CapacityOverflow >
1135
+ fn try_entry2 < K > ( & mut self , key : K ) -> Result < Entry < ' _ , T > , MaxSizeReached >
1136
1136
where
1137
1137
K : Hash + Into < HeaderName > ,
1138
1138
HeaderName : PartialEq < K > ,
@@ -1234,15 +1234,15 @@ impl<T> HeaderMap<T> {
1234
1234
/// let mut prev = map.try_insert(HOST, "earth".parse().unwrap()).unwrap().unwrap();
1235
1235
/// assert_eq!("world", prev);
1236
1236
/// ```
1237
- pub fn try_insert < K > ( & mut self , key : K , val : T ) -> Result < Option < T > , CapacityOverflow >
1237
+ pub fn try_insert < K > ( & mut self , key : K , val : T ) -> Result < Option < T > , MaxSizeReached >
1238
1238
where
1239
1239
K : IntoHeaderName ,
1240
1240
{
1241
1241
key. try_insert ( self , val)
1242
1242
}
1243
1243
1244
1244
#[ inline]
1245
- fn try_insert2 < K > ( & mut self , key : K , value : T ) -> Result < Option < T > , CapacityOverflow >
1245
+ fn try_insert2 < K > ( & mut self , key : K , value : T ) -> Result < Option < T > , MaxSizeReached >
1246
1246
where
1247
1247
K : Hash + Into < HeaderName > ,
1248
1248
HeaderName : PartialEq < K > ,
@@ -1374,15 +1374,15 @@ impl<T> HeaderMap<T> {
1374
1374
/// assert_eq!("world", *i.next().unwrap());
1375
1375
/// assert_eq!("earth", *i.next().unwrap());
1376
1376
/// ```
1377
- pub fn try_append < K > ( & mut self , key : K , value : T ) -> Result < bool , CapacityOverflow >
1377
+ pub fn try_append < K > ( & mut self , key : K , value : T ) -> Result < bool , MaxSizeReached >
1378
1378
where
1379
1379
K : IntoHeaderName ,
1380
1380
{
1381
1381
key. try_append ( self , value)
1382
1382
}
1383
1383
1384
1384
#[ inline]
1385
- fn try_append2 < K > ( & mut self , key : K , value : T ) -> Result < bool , CapacityOverflow >
1385
+ fn try_append2 < K > ( & mut self , key : K , value : T ) -> Result < bool , MaxSizeReached >
1386
1386
where
1387
1387
K : Hash + Into < HeaderName > ,
1388
1388
HeaderName : PartialEq < K > ,
@@ -1458,7 +1458,7 @@ impl<T> HeaderMap<T> {
1458
1458
hash : HashValue ,
1459
1459
probe : usize ,
1460
1460
danger : bool ,
1461
- ) -> Result < usize , CapacityOverflow > {
1461
+ ) -> Result < usize , MaxSizeReached > {
1462
1462
// Push the value and get the index
1463
1463
let index = self . entries . len ( ) ;
1464
1464
self . try_insert_entry ( hash, key, value) ?;
@@ -1592,9 +1592,9 @@ impl<T> HeaderMap<T> {
1592
1592
}
1593
1593
1594
1594
#[ inline]
1595
- fn try_insert_entry ( & mut self , hash : HashValue , key : HeaderName , value : T ) -> Result < ( ) , CapacityOverflow > {
1595
+ fn try_insert_entry ( & mut self , hash : HashValue , key : HeaderName , value : T ) -> Result < ( ) , MaxSizeReached > {
1596
1596
if self . entries . len ( ) >= MAX_SIZE {
1597
- return Err ( CapacityOverflow :: new ( ) ) ;
1597
+ return Err ( MaxSizeReached :: new ( ) ) ;
1598
1598
}
1599
1599
1600
1600
self . entries . push ( Bucket {
@@ -1654,7 +1654,7 @@ impl<T> HeaderMap<T> {
1654
1654
}
1655
1655
}
1656
1656
1657
- fn try_reserve_one ( & mut self ) -> Result < ( ) , CapacityOverflow > {
1657
+ fn try_reserve_one ( & mut self ) -> Result < ( ) , MaxSizeReached > {
1658
1658
let len = self . entries . len ( ) ;
1659
1659
1660
1660
if self . danger . is_yellow ( ) {
@@ -1695,9 +1695,9 @@ impl<T> HeaderMap<T> {
1695
1695
}
1696
1696
1697
1697
#[ inline]
1698
- fn try_grow ( & mut self , new_raw_cap : usize ) -> Result < ( ) , CapacityOverflow > {
1698
+ fn try_grow ( & mut self , new_raw_cap : usize ) -> Result < ( ) , MaxSizeReached > {
1699
1699
if new_raw_cap > MAX_SIZE {
1700
- return Err ( CapacityOverflow :: new ( ) ) ;
1700
+ return Err ( MaxSizeReached :: new ( ) ) ;
1701
1701
}
1702
1702
1703
1703
// find first ideally placed element -- start of cluster
@@ -2472,7 +2472,7 @@ impl<'a, T> Entry<'a, T> {
2472
2472
/// assert_eq!(map["content-length"], 2);
2473
2473
/// assert_eq!(map["x-hello"], 1);
2474
2474
/// ```
2475
- pub fn or_try_insert ( self , default : T ) -> Result < & ' a mut T , CapacityOverflow > {
2475
+ pub fn or_try_insert ( self , default : T ) -> Result < & ' a mut T , MaxSizeReached > {
2476
2476
use self :: Entry :: * ;
2477
2477
2478
2478
match self {
@@ -2557,7 +2557,7 @@ impl<'a, T> Entry<'a, T> {
2557
2557
///
2558
2558
/// assert_eq!(res, "world");
2559
2559
/// ```
2560
- pub fn or_try_insert_with < F : FnOnce ( ) -> T > ( self , default : F ) -> Result < & ' a mut T , CapacityOverflow > {
2560
+ pub fn or_try_insert_with < F : FnOnce ( ) -> T > ( self , default : F ) -> Result < & ' a mut T , MaxSizeReached > {
2561
2561
use self :: Entry :: * ;
2562
2562
2563
2563
match self {
@@ -2657,7 +2657,7 @@ impl<'a, T> VacantEntry<'a, T> {
2657
2657
///
2658
2658
/// assert_eq!(map["x-hello"], "world");
2659
2659
/// ```
2660
- pub fn try_insert ( self , value : T ) -> Result < & ' a mut T , CapacityOverflow > {
2660
+ pub fn try_insert ( self , value : T ) -> Result < & ' a mut T , MaxSizeReached > {
2661
2661
// Ensure that there is space in the map
2662
2662
let index =
2663
2663
self . map
@@ -2706,7 +2706,7 @@ impl<'a, T> VacantEntry<'a, T> {
2706
2706
///
2707
2707
/// assert_eq!(map["x-hello"], "world2");
2708
2708
/// ```
2709
- pub fn try_insert_entry ( self , value : T ) -> Result < OccupiedEntry < ' a , T > , CapacityOverflow > {
2709
+ pub fn try_insert_entry ( self , value : T ) -> Result < OccupiedEntry < ' a , T > , MaxSizeReached > {
2710
2710
// Ensure that there is space in the map
2711
2711
let index =
2712
2712
self . map
@@ -3534,7 +3534,7 @@ where
3534
3534
*/
3535
3535
3536
3536
mod into_header_name {
3537
- use crate :: error:: CapacityOverflow ;
3537
+ use crate :: error:: MaxSizeReached ;
3538
3538
use super :: { Entry , HdrName , HeaderMap , HeaderName } ;
3539
3539
3540
3540
/// A marker trait used to identify values that can be used as insert keys
@@ -3551,30 +3551,30 @@ mod into_header_name {
3551
3551
// without breaking any external crate.
3552
3552
pub trait Sealed {
3553
3553
#[ doc( hidden) ]
3554
- fn try_insert < T > ( self , map : & mut HeaderMap < T > , val : T ) -> Result < Option < T > , CapacityOverflow > ;
3554
+ fn try_insert < T > ( self , map : & mut HeaderMap < T > , val : T ) -> Result < Option < T > , MaxSizeReached > ;
3555
3555
3556
3556
#[ doc( hidden) ]
3557
- fn try_append < T > ( self , map : & mut HeaderMap < T > , val : T ) -> Result < bool , CapacityOverflow > ;
3557
+ fn try_append < T > ( self , map : & mut HeaderMap < T > , val : T ) -> Result < bool , MaxSizeReached > ;
3558
3558
3559
3559
#[ doc( hidden) ]
3560
- fn try_entry < T > ( self , map : & mut HeaderMap < T > ) -> Result < Entry < ' _ , T > , CapacityOverflow > ;
3560
+ fn try_entry < T > ( self , map : & mut HeaderMap < T > ) -> Result < Entry < ' _ , T > , MaxSizeReached > ;
3561
3561
}
3562
3562
3563
3563
// ==== impls ====
3564
3564
3565
3565
impl Sealed for HeaderName {
3566
3566
#[ inline]
3567
- fn try_insert < T > ( self , map : & mut HeaderMap < T > , val : T ) -> Result < Option < T > , CapacityOverflow > {
3567
+ fn try_insert < T > ( self , map : & mut HeaderMap < T > , val : T ) -> Result < Option < T > , MaxSizeReached > {
3568
3568
map. try_insert2 ( self , val)
3569
3569
}
3570
3570
3571
3571
#[ inline]
3572
- fn try_append < T > ( self , map : & mut HeaderMap < T > , val : T ) -> Result < bool , CapacityOverflow > {
3572
+ fn try_append < T > ( self , map : & mut HeaderMap < T > , val : T ) -> Result < bool , MaxSizeReached > {
3573
3573
map. try_append2 ( self , val)
3574
3574
}
3575
3575
3576
3576
#[ inline]
3577
- fn try_entry < T > ( self , map : & mut HeaderMap < T > ) -> Result < Entry < ' _ , T > , CapacityOverflow > {
3577
+ fn try_entry < T > ( self , map : & mut HeaderMap < T > ) -> Result < Entry < ' _ , T > , MaxSizeReached > {
3578
3578
map. try_entry2 ( self )
3579
3579
}
3580
3580
}
@@ -3583,16 +3583,16 @@ mod into_header_name {
3583
3583
3584
3584
impl < ' a > Sealed for & ' a HeaderName {
3585
3585
#[ inline]
3586
- fn try_insert < T > ( self , map : & mut HeaderMap < T > , val : T ) -> Result < Option < T > , CapacityOverflow > {
3586
+ fn try_insert < T > ( self , map : & mut HeaderMap < T > , val : T ) -> Result < Option < T > , MaxSizeReached > {
3587
3587
map. try_insert2 ( self , val)
3588
3588
}
3589
3589
#[ inline]
3590
- fn try_append < T > ( self , map : & mut HeaderMap < T > , val : T ) -> Result < bool , CapacityOverflow > {
3590
+ fn try_append < T > ( self , map : & mut HeaderMap < T > , val : T ) -> Result < bool , MaxSizeReached > {
3591
3591
map. try_append2 ( self , val)
3592
3592
}
3593
3593
3594
3594
#[ inline]
3595
- fn try_entry < T > ( self , map : & mut HeaderMap < T > ) -> Result < Entry < ' _ , T > , CapacityOverflow > {
3595
+ fn try_entry < T > ( self , map : & mut HeaderMap < T > ) -> Result < Entry < ' _ , T > , MaxSizeReached > {
3596
3596
map. try_entry2 ( self )
3597
3597
}
3598
3598
}
@@ -3601,16 +3601,16 @@ mod into_header_name {
3601
3601
3602
3602
impl Sealed for & ' static str {
3603
3603
#[ inline]
3604
- fn try_insert < T > ( self , map : & mut HeaderMap < T > , val : T ) -> Result < Option < T > , CapacityOverflow > {
3604
+ fn try_insert < T > ( self , map : & mut HeaderMap < T > , val : T ) -> Result < Option < T > , MaxSizeReached > {
3605
3605
HdrName :: from_static ( self , move |hdr| map. try_insert2 ( hdr, val) )
3606
3606
}
3607
3607
#[ inline]
3608
- fn try_append < T > ( self , map : & mut HeaderMap < T > , val : T ) -> Result < bool , CapacityOverflow > {
3608
+ fn try_append < T > ( self , map : & mut HeaderMap < T > , val : T ) -> Result < bool , MaxSizeReached > {
3609
3609
HdrName :: from_static ( self , move |hdr| map. try_append2 ( hdr, val) )
3610
3610
}
3611
3611
3612
3612
#[ inline]
3613
- fn try_entry < T > ( self , map : & mut HeaderMap < T > ) -> Result < Entry < ' _ , T > , CapacityOverflow > {
3613
+ fn try_entry < T > ( self , map : & mut HeaderMap < T > ) -> Result < Entry < ' _ , T > , MaxSizeReached > {
3614
3614
HdrName :: from_static ( self , move |hdr| map. try_entry2 ( hdr) )
3615
3615
}
3616
3616
}
0 commit comments