Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ enum ErrorKind {
UriParts(uri::InvalidUriParts),
HeaderName(header::InvalidHeaderName),
HeaderValue(header::InvalidHeaderValue),
MaxSizeReached(MaxSizeReached),
}

impl fmt::Debug for Error {
Expand Down Expand Up @@ -61,6 +62,7 @@ impl Error {
UriParts(ref e) => e,
HeaderName(ref e) => e,
HeaderValue(ref e) => e,
MaxSizeReached(ref e) => e,
}
}
}
Expand All @@ -73,6 +75,14 @@ impl error::Error for Error {
}
}

impl From<MaxSizeReached> for Error {
fn from(err: MaxSizeReached) -> Error {
Error {
inner: ErrorKind::MaxSizeReached(err),
}
}
}

impl From<status::InvalidStatusCode> for Error {
fn from(err: status::InvalidStatusCode) -> Error {
Error {
Expand Down Expand Up @@ -127,6 +137,35 @@ impl From<std::convert::Infallible> for Error {
}
}

/// Error returned when max capacity of `HeaderMap` is exceeded
pub struct MaxSizeReached {
_priv: (),
}

impl MaxSizeReached {
/// Create new `MaxSizeReached` instance
pub fn new() -> MaxSizeReached {
MaxSizeReached { _priv: () }
}
}

impl fmt::Debug for MaxSizeReached {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("MaxSizeReached")
// skip _priv noise
.finish()
}
}

impl fmt::Display for MaxSizeReached {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("max size reached")
}
}

impl std::error::Error for MaxSizeReached {}


#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading