pub struct Code<C: ComponentId, P: PrimaryId> { /* private fields */ }Expand description
Waddling diagnostic code: SEVERITY.COMPONENT.PRIMARY.SEQUENCE
Format: E.CRYPTO.SALT.001
This type is generic over component and primary types that implement
the ComponentId and PrimaryId traits. This allows full type safety
while maintaining extensibility.
§Examples
Define your own component and primary enums:
use waddling_errors::{Code, ComponentId, PrimaryId};
#[derive(Debug, Clone, Copy)]
enum Component { Crypto }
impl ComponentId for Component {
fn as_str(&self) -> &'static str { "CRYPTO" }
}
#[derive(Debug, Clone, Copy)]
enum Primary { Salt }
impl PrimaryId for Primary {
fn as_str(&self) -> &'static str { "SALT" }
}
const ERR: Code<Component, Primary> = Code::error(Component::Crypto, Primary::Salt, 1);
assert_eq!(ERR.code(), "E.CRYPTO.SALT.001");Implementations§
Source§impl<C: ComponentId, P: PrimaryId> Code<C, P>
impl<C: ComponentId, P: PrimaryId> Code<C, P>
Sourcepub const fn warning(component: C, primary: P, sequence: u16) -> Self
pub const fn warning(component: C, primary: P, sequence: u16) -> Self
Create a warning code (W)
Sourcepub const fn critical(component: C, primary: P, sequence: u16) -> Self
pub const fn critical(component: C, primary: P, sequence: u16) -> Self
Create a critical code (C)
Sourcepub const fn blocked(component: C, primary: P, sequence: u16) -> Self
pub const fn blocked(component: C, primary: P, sequence: u16) -> Self
Create a blocked code (B)
Sourcepub const fn success(component: C, primary: P, sequence: u16) -> Self
pub const fn success(component: C, primary: P, sequence: u16) -> Self
Create a success code (S)
Sourcepub const fn completed(component: C, primary: P, sequence: u16) -> Self
pub const fn completed(component: C, primary: P, sequence: u16) -> Self
Create a completed code (K)
Sourcepub fn write_code(&self, f: &mut impl Write) -> Result
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.
Sourcepub fn component_str(&self) -> &'static str
pub fn component_str(&self) -> &'static str
Get component as string
Sourcepub fn primary_str(&self) -> &'static str
pub fn primary_str(&self) -> &'static str
Get primary as string
Trait Implementations§
impl<C: Copy + ComponentId, P: Copy + PrimaryId> Copy for Code<C, P>
impl<C: Eq + ComponentId, P: Eq + PrimaryId> Eq for Code<C, P>
impl<C: ComponentId, P: PrimaryId> StructuralPartialEq for Code<C, P>
Auto Trait Implementations§
impl<C, P> Freeze for Code<C, P>
impl<C, P> RefUnwindSafe for Code<C, P>where
C: RefUnwindSafe,
P: RefUnwindSafe,
impl<C, P> Send for Code<C, P>
impl<C, P> Sync for Code<C, P>
impl<C, P> Unpin for Code<C, P>
impl<C, P> UnwindSafe for Code<C, P>where
C: UnwindSafe,
P: UnwindSafe,
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