Code

Struct Code 

Source
pub struct Code { /* private fields */ }
Expand description

Waddling diagnostic code: SEVERITY.COMPONENT.PRIMARY.SEQUENCE

Format: E.CRYPTO.SALT.001

§Examples

use waddling_errors::{Code, Severity};

const ERR: Code = Code::error("CRYPTO", "SALT", 1);
assert_eq!(ERR.code(), "E.CRYPTO.SALT.001");

Implementations§

Source§

impl Code

Source

pub const fn new( severity: Severity, component: &'static str, primary: &'static str, sequence: u16, ) -> Self

Create a new code with explicit severity

§Panics

Panics if sequence > 999, or component/primary length not in 2-12 range

Source

pub const fn error( component: &'static str, primary: &'static str, sequence: u16, ) -> Self

Create an error code (E)

Source

pub const fn warning( component: &'static str, primary: &'static str, sequence: u16, ) -> Self

Create a warning code (W)

Source

pub const fn critical( component: &'static str, primary: &'static str, sequence: u16, ) -> Self

Create a critical code (C)

Source

pub const fn blocked( component: &'static str, primary: &'static str, sequence: u16, ) -> Self

Create a blocked code (B)

Source

pub const fn help( component: &'static str, primary: &'static str, sequence: u16, ) -> Self

Create a help code (H)

Source

pub const fn success( component: &'static str, primary: &'static str, sequence: u16, ) -> Self

Create a success code (S)

Source

pub const fn completed( component: &'static str, primary: &'static str, sequence: u16, ) -> Self

Create a completed code (K)

Source

pub const fn info( component: &'static str, primary: &'static str, sequence: u16, ) -> Self

Create an info code (I)

Source

pub const fn trace( component: &'static str, primary: &'static str, sequence: u16, ) -> Self

Create a trace code (T)

Source

pub fn code(&self) -> String

Get the full error code (e.g., “E.CRYPTO.SALT.001”)

Source

pub fn write_code(&self, f: &mut impl Write) -> Result

Write error code to formatter without allocating

Use in performance-critical paths to avoid String allocation.

Source

pub const fn severity(&self) -> Severity

Get severity

Source

pub const fn component(&self) -> &'static str

Get component

Source

pub const fn primary(&self) -> &'static str

Get primary category

Source

pub const fn sequence(&self) -> u16

Get sequence number

Trait Implementations§

Source§

impl Clone for Code

Source§

fn clone(&self) -> Code

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 Code

Source§

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

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

impl Display for Code

Source§

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

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

impl Hash for Code

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Code

Source§

fn eq(&self, other: &Code) -> 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 Copy for Code

Source§

impl Eq for Code

Source§

impl StructuralPartialEq for Code

Auto Trait Implementations§

§

impl Freeze for Code

§

impl RefUnwindSafe for Code

§

impl Send for Code

§

impl Sync for Code

§

impl Unpin for Code

§

impl UnwindSafe for Code

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