pub struct ErrorResponse {
pub error: ErrorCode,
pub error_description: Option<Cow<'static, str>>,
pub error_uri: Option<Cow<'static, str>>,
}Expand description
The RFC 6749 section 5.2 error response body: error required, error_description and
error_uri optional and omitted (never null) when absent.
§Why the two optional fields are Cow<'static, str> and not String
This is the type every REFUSAL in this crate is built out of, and a refusal is the one response
an attacker chooses the rate of: an unauthenticated caller can ask for as many invalid_request
bodies as it can open sockets for, and asks for none of the successful ones. Roughly 50 of the
crate’s 57 description sites pass a string constant, so an owned String meant one heap copy
of a &'static str per refused request, bought for nothing.
It is free in memory as well as in allocations: Option<Cow<'static, str>> is 24 bytes, the
SAME as Option<String>, because Cow’s discriminant lives in the niche the pointer already
has. MEASURED, not assumed: ErrorResponse is 56 bytes before and after, and
tests/allocation.rs pins both that size and the zero-allocation claim.
A host that needs a description it computed still passes a String: Cow owns that case, and
ErrorResponse::with_description takes impl Into<Cow<'static, str>> so both spellings
compile unchanged.
Fields§
§error: ErrorCodeThe registered error code.
error_description: Option<Cow<'static, str>>Human-readable ASCII detail for the developer (not the end user), per section 5.2.
error_uri: Option<Cow<'static, str>>A URI identifying a human-readable page with more information.
Implementations§
Source§impl ErrorResponse
impl ErrorResponse
Sourcepub fn with_description(self, description: impl Into<Cow<'static, str>>) -> Self
pub fn with_description(self, description: impl Into<Cow<'static, str>>) -> Self
Attach a developer-facing description.
impl Into<Cow<'static, str>>, so a &'static str borrows and a String moves: the
overwhelmingly common caller passes a literal and pays nothing, and a caller that genuinely
computed the text keeps working with no change at the call site.
Sourcepub fn with_uri(self, uri: impl Into<Cow<'static, str>>) -> Self
pub fn with_uri(self, uri: impl Into<Cow<'static, str>>) -> Self
Attach an error_uri (RFC 6749 section 5.2), the same way and for the same reason.
Sourcepub fn http_status(&self) -> u16
pub fn http_status(&self) -> u16
The HTTP status for this response; see ErrorCode::http_status.
Trait Implementations§
Source§impl Clone for ErrorResponse
impl Clone for ErrorResponse
Source§fn clone(&self) -> ErrorResponse
fn clone(&self) -> ErrorResponse
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ErrorResponse
impl Debug for ErrorResponse
Source§impl<'de> Deserialize<'de> for ErrorResponse
impl<'de> Deserialize<'de> for ErrorResponse
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for ErrorResponse
impl Display for ErrorResponse
impl Eq for ErrorResponse
Source§impl Error for ErrorResponse
impl Error for ErrorResponse
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<StepUpFailure> for ErrorResponse
Available on crate feature consent only.
impl From<StepUpFailure> for ErrorResponse
consent only.