Skip to main content

ErrorResponse

Struct ErrorResponse 

Source
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: ErrorCode

The 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

Source

pub fn new(error: ErrorCode) -> Self

A bare error with no description.

Source

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.

Source

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.

Source

pub fn http_status(&self) -> u16

The HTTP status for this response; see ErrorCode::http_status.

Trait Implementations§

Source§

impl Clone for ErrorResponse

Source§

fn clone(&self) -> ErrorResponse

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ErrorResponse

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ErrorResponse

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for ErrorResponse

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for ErrorResponse

Source§

impl Error for ErrorResponse

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<StepUpFailure> for ErrorResponse

Available on crate feature consent only.
Source§

fn from(failure: StepUpFailure) -> ErrorResponse

Converts to this type from the input type.
Source§

impl PartialEq for ErrorResponse

Source§

fn eq(&self, other: &ErrorResponse) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ErrorResponse

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ErrorResponse

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.