Skip to content

Commit 54a1525

Browse files
committed
try_ methods to handle capacity overflow
1 parent 78e3d37 commit 54a1525

File tree

5 files changed

+501
-171
lines changed

5 files changed

+501
-171
lines changed

src/error.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ enum ErrorKind {
2727
UriParts(uri::InvalidUriParts),
2828
HeaderName(header::InvalidHeaderName),
2929
HeaderValue(header::InvalidHeaderValue),
30+
MaxSizeReached(MaxSizeReached),
3031
}
3132

3233
impl fmt::Debug for Error {
@@ -61,6 +62,7 @@ impl Error {
6162
UriParts(ref e) => e,
6263
HeaderName(ref e) => e,
6364
HeaderValue(ref e) => e,
65+
MaxSizeReached(ref e) => e,
6466
}
6567
}
6668
}
@@ -73,6 +75,14 @@ impl error::Error for Error {
7375
}
7476
}
7577

78+
impl From<MaxSizeReached> for Error {
79+
fn from(err: MaxSizeReached) -> Error {
80+
Error {
81+
inner: ErrorKind::MaxSizeReached(err),
82+
}
83+
}
84+
}
85+
7686
impl From<status::InvalidStatusCode> for Error {
7787
fn from(err: status::InvalidStatusCode) -> Error {
7888
Error {
@@ -127,6 +137,35 @@ impl From<std::convert::Infallible> for Error {
127137
}
128138
}
129139

140+
/// Error returned when max capacity of `HeaderMap` is exceeded
141+
pub struct MaxSizeReached {
142+
_priv: (),
143+
}
144+
145+
impl MaxSizeReached {
146+
/// Create new `MaxSizeReached` instance
147+
pub fn new() -> MaxSizeReached {
148+
MaxSizeReached { _priv: () }
149+
}
150+
}
151+
152+
impl fmt::Debug for MaxSizeReached {
153+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
154+
f.debug_struct("MaxSizeReached")
155+
// skip _priv noise
156+
.finish()
157+
}
158+
}
159+
160+
impl fmt::Display for MaxSizeReached {
161+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
162+
f.write_str("max size reached")
163+
}
164+
}
165+
166+
impl std::error::Error for MaxSizeReached {}
167+
168+
130169
#[cfg(test)]
131170
mod tests {
132171
use super::*;

0 commit comments

Comments
 (0)