#[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
impl Severity
Sourcepub const fn level(self) -> u8
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?
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}Sourcepub const fn is_positive(self) -> bool
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?
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
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}