Severity

Enum Severity 

Source
#[repr(u8)]
pub enum Severity { Error = 69, Warning = 87, Critical = 67, Blocked = 66, Success = 83, Completed = 75, Info = 73, Trace = 84, }
Expand description

Diagnostic message severity level (single-character prefix for 4-part codes)

Represents the severity/type of a diagnostic code. Each severity gets a single-character prefix in the 4-part format: SEVERITY.COMPONENT.PRIMARY.SEQUENCE

§Available Severities

  • Error (E) - Operation failed
  • Warning (W) - Potential issue
  • Critical (C) - Severe issue
  • Blocked (B) - Execution blocked
  • Success (S) - Operation succeeded
  • Completed (K) - Task/phase finished
  • Info (I) - Informational events
  • Trace (T) - Execution traces, probes

§Examples

use waddling_errors::{Code, Severity};

const ERR: Code = Code::new(Severity::Error, "io", "FILE", 1);
const WARN: Code = Code::new(Severity::Warning, "api", "DEPR", 1);

assert_eq!(ERR.severity().as_char(), 'E');
assert_eq!(WARN.severity().as_char(), 'W');

Variants§

§

Error = 69

Error (E) - Operation failed

Example: invalid input, parse error, type mismatch, auth failure

§

Warning = 87

Warning (W) - Potential issue or caveat

Example: deprecated API, performance concern, edge case

§

Critical = 67

Critical (C) - Severe issue requiring attention

Example: data corruption, security breach, checksum fail

§

Blocked = 66

Blocked (B) - Execution blocked/waiting

Example: deadlock, I/O wait, network unavailable, resource locked

§

Success = 83

Success (S) - Operation succeeded

Example: compilation successful, tests passed, deployment complete

§

Completed = 75

Completed (K) - Task or phase completed

Example: parsing complete, type-checking done, optimization finished

§

Info = 73

Info (I) - General informational events

Example: server started, config loaded, milestone reached, status updates

§

Trace = 84

Trace (T) - Execution traces and instrumentation

Example: probe data, function entry/exit, timing measurements, thread events

Implementations§

Source§

impl Severity

Source

pub const fn as_char(self) -> char

Get the single-character code (E, W, C, B, S, K, I, T)

Source

pub const fn level(self) -> u8

Get the severity level as a number (for ordering/filtering)

Higher numbers = more severe/important (Trace=0 … Error=7)

Note: Success/Completed are treated as low-priority (similar to Info/Trace) since they’re positive outcomes that don’t require immediate action.

Examples found in repository?
examples/severity_matrix.rs (line 59)
53fn print_error_analysis(code: &ErrorCode, description: &str) {
54    println!("╔══════════════════════════════════════════════════════════════╗");
55    println!("║ Code: {:<54} ║", code.code());
56    println!("║ Description: {:<47} ║", description);
57    println!("╠══════════════════════════════════════════════════════════════╣");
58    println!("║ Severity: {:<50} ║", format!("{:?}", code.severity()));
59    println!("║ Level: {:<53} ║", code.severity().level());
60    println!(
61        "║ Positive: {:<50} ║",
62        if code.severity().is_positive() {
63            "YES ✓"
64        } else {
65            "NO ✗"
66        }
67    );
68    println!("╚══════════════════════════════════════════════════════════════╝");
69    println!();
70}
Source

pub const fn is_positive(self) -> bool

Check if this severity represents a positive outcome (success/completion)

Returns true for Success and Completed severities.

Examples found in repository?
examples/severity_matrix.rs (line 62)
53fn print_error_analysis(code: &ErrorCode, description: &str) {
54    println!("╔══════════════════════════════════════════════════════════════╗");
55    println!("║ Code: {:<54} ║", code.code());
56    println!("║ Description: {:<47} ║", description);
57    println!("╠══════════════════════════════════════════════════════════════╣");
58    println!("║ Severity: {:<50} ║", format!("{:?}", code.severity()));
59    println!("║ Level: {:<53} ║", code.severity().level());
60    println!(
61        "║ Positive: {:<50} ║",
62        if code.severity().is_positive() {
63            "YES ✓"
64        } else {
65            "NO ✗"
66        }
67    );
68    println!("╚══════════════════════════════════════════════════════════════╝");
69    println!();
70}
More examples
Hide additional examples
examples/standalone.rs (line 165)
100fn main() {
101    println!("🦆 Waddling-Errors Standalone Demo 🦆\n");
102    println!("Zero external dependencies - just pure error codes!\n");
103
104    // Example 1: Custom error type
105    println!("═══════════════════════════════════════════════════");
106    println!("Example 1: Custom Error Type with ErrorCode");
107    println!("═══════════════════════════════════════════════════");
108
109    match validate_age(-5) {
110        Ok(_) => println!("✓ Age valid"),
111        Err(e) => {
112            println!("✗ Error: {}", e);
113            println!("  Code: {}", e.code().code());
114            println!("  Severity: {:?}", e.code().severity());
115        }
116    }
117    println!();
118
119    // Example 2: Not found error
120    println!("═══════════════════════════════════════════════════");
121    println!("Example 2: Data Not Found");
122    println!("═══════════════════════════════════════════════════");
123
124    match find_user(0) {
125        Ok(user) => println!("✓ Found: {}", user),
126        Err(e) => {
127            println!("✗ Error: {}", e);
128            println!("  Code: {}", e.code().code());
129        }
130    }
131    println!();
132
133    // Example 3: Warnings
134    println!("═══════════════════════════════════════════════════");
135    println!("Example 3: Warnings");
136    println!("═══════════════════════════════════════════════════");
137
138    match process_with_warnings("old_api_call()") {
139        Ok(result) => println!("✓ Processed (with warnings): {}", result),
140        Err(e) => println!("✗ Failed: {}", e),
141    }
142    println!();
143
144    // Example 4: Direct ErrorCode returns (ultra minimal)
145    println!("═══════════════════════════════════════════════════");
146    println!("Example 4: Direct ErrorCode Returns (Ultra Minimal)");
147    println!("═══════════════════════════════════════════════════");
148
149    match quick_validate(-10) {
150        Ok(val) => println!("✓ Result: {}", val),
151        Err(code) => {
152            println!("✗ Failed with code: {}", code.code());
153            println!("  Just the error code - no wrapper type needed!");
154        }
155    }
156    println!();
157
158    // Example 5: Success codes
159    println!("═══════════════════════════════════════════════════");
160    println!("Example 5: Success Codes (Active Diagnostic Systems)");
161    println!("═══════════════════════════════════════════════════");
162
163    println!("Task completed!");
164    println!("  Code: {}", SUCCESS_COMPLETE.code());
165    println!("  Positive: {}", SUCCESS_COMPLETE.severity().is_positive());
166    println!("  Active systems can celebrate success! 🎉");
167    println!();
168
169    // Summary
170    println!("═══════════════════════════════════════════════════");
171    println!("Key Takeaways");
172    println!("═══════════════════════════════════════════════════");
173    println!("✓ No external dependencies (thiserror/anyhow optional)");
174    println!("✓ Error codes are const fn (zero runtime cost)");
175    println!("✓ Works in no_std environments");
176    println!("✓ ~500 bytes binary size overhead");
177    println!("✓ DIY error types or direct ErrorCode returns");
178    println!("✓ Full control over error handling");
179    println!("\n🦆 Pure, lightweight, flexible! 🦆\n");
180}

Trait Implementations§

Source§

impl Clone for Severity

Source§

fn clone(&self) -> Severity

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 Severity

Source§

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

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

impl Display for Severity

Source§

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

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

impl Hash for Severity

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 Severity

Source§

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

Source§

impl Eq for Severity

Source§

impl StructuralPartialEq for Severity

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