pub struct ErrorCode(/* private fields */);Expand description
A stable, machine-readable error code for logs and API responses.
Codes follow a domain.reason convention (e.g. config.missing_required,
data.unavailable). They are usually &'static str constants, but a dynamic
String is supported for codes assembled at runtime.
Implementations§
Source§impl ErrorCode
impl ErrorCode
Sourcepub fn from_string(code: String) -> Self
pub fn from_string(code: String) -> Self
A code assembled at runtime.
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
The code as a string slice.
Examples found in repository?
examples/error_kernel.rs (line 53)
45fn main() {
46 let errors = [OrderError::NotFound, OrderError::PaymentDeclined, OrderError::LedgerUnavailable];
47
48 println!("{:<32} {:<28} {:>4} retryable", "error", "code", "http");
49 for err in &errors {
50 let code = err.code();
51 println!(
52 "{err:<32} {:<28} {:>4} {}",
53 code.as_str(),
54 err.http_status(),
55 err.is_retryable(),
56 );
57 }
58}Trait Implementations§
Source§impl<'de> Deserialize<'de> for ErrorCode
impl<'de> Deserialize<'de> for ErrorCode
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for ErrorCode
impl StructuralPartialEq for ErrorCode
Auto Trait Implementations§
impl Freeze for ErrorCode
impl RefUnwindSafe for ErrorCode
impl Send for ErrorCode
impl Sync for ErrorCode
impl Unpin for ErrorCode
impl UnsafeUnpin for ErrorCode
impl UnwindSafe for ErrorCode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more