Skip to main content

ProblemDetails

Struct ProblemDetails 

Source
pub struct ProblemDetails {
    pub status: StatusCode,
    pub title: String,
    pub detail: Option<String>,
    pub extra: Box<Map<String, Value>>,
}
Expand description

Structured error response shaped like an RFC 7807 Problem Details document, plus arbitrary extension members that get serialized into the JSON body.

Use this when one of the simple WebError::* variants doesn’t carry enough information (e.g., a validation failure that wants to name the failing field and rule).

return Err(WebError::Problem(
    ProblemDetails::new(StatusCode::CONFLICT, "Validation")
        .detail("title is required")
        .extra("field", "data.title")
        .extra("rule", "required"),
));

Wire shape (application/problem+json):

{ "status": 409, "title": "Validation", "detail": "title is required",
  "field": "data.title", "rule": "required" }

Fields§

§status: StatusCode

The HTTP status code, serialized as the status member.

§title: String

A short, human-readable summary, serialized as the title member.

§detail: Option<String>

An optional longer explanation, serialized as the detail member.

§extra: Box<Map<String, Value>>

Extension members. Serialized alongside status / title / detail. Keys that collide with the standard members are ignored.

Boxed to keep WebError small: this map dominates the struct’s size, yet extensions are optional and most errors carry none — so the common case pays one pointer, not a full inline map, on every Result return.

Implementations§

Source§

impl ProblemDetails

Source

pub fn new(status: StatusCode, title: impl Into<String>) -> ProblemDetails

Construct a new problem with the given status code and title.

Source

pub fn detail(self, detail: impl Into<String>) -> ProblemDetails

Set the human-readable detail message.

Source

pub fn extra( self, key: impl Into<String>, value: impl Into<Value>, ) -> ProblemDetails

Add an extension member. Use any JSON-serializable value via .into(), serde_json::json!(…), or serde_json::to_value(…).

Trait Implementations§

Source§

impl Clone for ProblemDetails

Source§

fn clone(&self) -> ProblemDetails

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 ProblemDetails

Source§

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

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

impl Display for ProblemDetails

Source§

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

Formats the value using the given formatter. Read more

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more