Skip to main content

ApiErrorBuilder

Struct ApiErrorBuilder 

Source
pub struct ApiErrorBuilder<C, D> { /* private fields */ }
Expand description

Typestate builder for ApiError.

Type parameters track whether required fields have been set:

  • CErrorCode once .code() is called, () otherwise
  • DString once .detail() is called, () otherwise

ApiErrorBuilder::build is only available when both are set.

Requires std or alloc.

Implementations§

Source§

impl<D> ApiErrorBuilder<(), D>

Source

pub fn code(self, code: ErrorCode) -> ApiErrorBuilder<ErrorCode, D>

Set the error code. title and status are derived from it automatically.

Source§

impl<C> ApiErrorBuilder<C, ()>

Source

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

Set the human-readable error detail message.

Source§

impl<C, D> ApiErrorBuilder<C, D>

Source

pub fn request_id(self, id: Uuid) -> Self

Attach a request ID.

Source

pub fn errors(self, errors: Vec<ValidationError>) -> Self

Attach structured field-level validation errors.

Source

pub fn causes(self, causes: Vec<ApiError>) -> Self

Attach a chain of nested cause errors (serialized as "causes").

Source§

impl ApiErrorBuilder<ErrorCode, String>

Source

pub fn build(self) -> ApiError

Build the ApiError.

Only available once both code and detail have been set.

Auto Trait Implementations§

§

impl<C, D> Freeze for ApiErrorBuilder<C, D>
where C: Freeze, D: Freeze,

§

impl<C, D> !RefUnwindSafe for ApiErrorBuilder<C, D>

§

impl<C, D> Send for ApiErrorBuilder<C, D>
where C: Send, D: Send,

§

impl<C, D> Sync for ApiErrorBuilder<C, D>
where C: Sync, D: Sync,

§

impl<C, D> Unpin for ApiErrorBuilder<C, D>
where C: Unpin, D: Unpin,

§

impl<C, D> UnsafeUnpin for ApiErrorBuilder<C, D>
where C: UnsafeUnpin, D: UnsafeUnpin,

§

impl<C, D> !UnwindSafe for ApiErrorBuilder<C, D>

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.