pub struct ProblemMeta {
pub slug: &'static str,
pub version: &'static str,
pub title: &'static str,
pub status: u16,
pub exit_code: u8,
}Expand description
Reusable per-variant problem-type metadata.
An implementing crate defines one ProblemMeta per error variant (slug,
version, title, status, exit code) and converts it to a full
ProblemDetails with ProblemMeta::into_details, keeping the
URI/version/status/exit-code bookkeeping for that crate’s errors in one
place — extending the enum means adding one match arm, not editing several
parallel constructions.
Fields§
§slug: &'static strStable, URL-safe slug for the problem type.
version: &'static strVersion segment of the type URI (e.g. "v1"). Per-type, so one type
can advance independently of the others.
title: &'static strShort, stable title for the problem type.
status: u16Numeric status class.
exit_code: u8Process exit code emitted alongside the error.
Implementations§
Source§impl ProblemMeta
impl ProblemMeta
Sourcepub fn type_uri(&self) -> String
pub fn type_uri(&self) -> String
The stable, version-embedded problem-type URI for this metadata.
Derived as {ERROR_TYPE_BASE_URI}/{slug}/{version}. The version is
the stability commitment: the meaning of a given URI never changes; a
breaking change to a problem type ships a new version (e.g. /v2)
rather than redefining the existing one.
§Returns
The fully-qualified type URI for this metadata.
Sourcepub fn into_details(
self,
crate_name: &str,
detail: impl Into<String>,
) -> ProblemDetails
pub fn into_details( self, crate_name: &str, detail: impl Into<String>, ) -> ProblemDetails
Builds a ProblemDetails from this metadata, an owning crate name,
and an occurrence-specific detail message.
§Arguments
crate_name- The implementing crate’s own name, e.g.env!("CARGO_PKG_NAME")evaluated at the call site (this macro must be invoked in the calling crate, not here, to expand correctly).detail- This-occurrence explanation, typically the error’s ownDisplaystring so the human and machine renderings never drift.
§Returns
A ProblemDetails with exit_code pre-populated from this
metadata; attach a suggested_fix/code_action with the with_*
methods as needed.
Trait Implementations§
Source§impl Clone for ProblemMeta
impl Clone for ProblemMeta
Source§fn clone(&self) -> ProblemMeta
fn clone(&self) -> ProblemMeta
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more