Skip to main content

ErrorTypeMode

Enum ErrorTypeMode 

Source
pub enum ErrorTypeMode {
    Url {
        base_url: String,
    },
    Urn {
        namespace: String,
    },
}
Expand description

How the RFC 9457 type field is rendered for ErrorCode.

RFC 9457 §3.1.1 requires type to be a URI reference and encourages using resolvable URLs so consumers can look up documentation. This enum lets you choose the format that fits your deployment.

Requires std or alloc (fields contain String).

§no_std note

This type is available with alloc alone, but the global accessors error_type_mode and set_error_type_mode require the std feature (RwLock + env-var access). In a no_std + alloc context, construct the variant you need and call ErrorTypeMode::render directly.

§Configuration

Set the mode once at startup via set_error_type_mode, or let it auto-resolve from environment variables (see error_type_mode).

Produces {base_url}/{slug}, e.g.: https://docs.myapp.com/errors/resource-not-found

Set via env: SHARED_TYPES_ERROR_TYPE_BASE_URL=https://docs.myapp.com/errors

§URN mode (fallback)

Produces urn:{namespace}:error:{slug}, e.g.: urn:myapp:error:resource-not-found

Set via env: SHARED_TYPES_URN_NAMESPACE=myapp

§Examples

use api_bones::error::ErrorTypeMode;

let url_mode = ErrorTypeMode::Url { base_url: "https://docs.example.com/errors".into() };
assert_eq!(url_mode.render("not-found"), "https://docs.example.com/errors/not-found");

let urn_mode = ErrorTypeMode::Urn { namespace: "myapp".into() };
assert_eq!(urn_mode.render("not-found"), "urn:myapp:error:not-found");

Variants§

§

Url

Generate a resolvable URL per RFC 9457 §3.1.1 (recommended). Format: {base_url}/{slug} — trailing slash in base_url is trimmed automatically.

Fields

§base_url: String

Base URL for error documentation, e.g. https://docs.myapp.com/errors.

§

Urn

Generate a URN per RFC 9457 §3.1.1 + RFC 8141. Format: urn:{namespace}:error:{slug}.

Fields

§namespace: String

URN namespace, e.g. "myapp".

Implementations§

Source§

impl ErrorTypeMode

Source

pub fn render(&self, slug: &str) -> String

Render the full type URI for a given error slug.

§Examples
use api_bones::error::ErrorTypeMode;

let mode = ErrorTypeMode::Url { base_url: "https://example.com/errors/".into() };
assert_eq!(mode.render("bad-request"), "https://example.com/errors/bad-request");

let mode = ErrorTypeMode::Urn { namespace: "acme".into() };
assert_eq!(mode.render("bad-request"), "urn:acme:error:bad-request");

Trait Implementations§

Source§

impl Clone for ErrorTypeMode

Source§

fn clone(&self) -> ErrorTypeMode

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ErrorTypeMode

Source§

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

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

impl PartialEq for ErrorTypeMode

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for ErrorTypeMode

Source§

impl StructuralPartialEq for ErrorTypeMode

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