๐ฆ waddling-sequences
Standard error sequence definitions for the Waddling ecosystem
What is this?
waddling-sequences provides standardized error sequence numbers with semantic meanings that are consistent across the entire Waddling ecosystem, following the WDP Part 6: Sequence Conventions specification.
Think of it like HTTP status codes for errors:
- Everyone knows
404 = Not Found - With Waddling: Everyone knows
001 = MISSING,003 = INVALID,021 = NOT_FOUND, etc.
Reference: WDP Part 6: Sequence Conventions (WDP-6)
Features
- โ Zero dependencies - Just pure constants (by default)
- โ No-std compatible - Works everywhere
- โ Tree-shakeable - Only imports what you use
- โ Universal - Works with any error library
- โ Well-documented - Every sequence has clear meaning
- โ WDP-6 Compliant - Follows official sequence conventions
- ๐ Optional metadata - Get rich documentation at runtime (
metadatafeature) - ๐ Optional doc generation - Generate HTML/JSON docs (
doc-genfeature) - ๐ง Optional macros - Full waddling-errors ecosystem integration (
macrosfeature)
Three Ways to Use
1. Pure Constants (Default - Zero Dependencies)
use *;
// Just numbers - minimal, no_std compatible
const MY_ERROR: u16 = MISSING; // 001
const OTHER_ERROR: u16 = NOT_FOUND; // 021
2. With Metadata (Runtime Documentation)
[]
= { = "0.2", = ["metadata"] }
use ;
// Query metadata at runtime
if let Some = get
3. With Macros (Full Ecosystem Integration)
[]
= { = "0.2", = ["macros"] }
= "0.6"
use ;
setup!
diag!
Quick Start
use *;
// Use standard sequences with semantic meaning
const MY_ERROR_CODE: u16 = MISSING; // 001 - always means "missing"
const OTHER_ERROR: u16 = MISMATCH; // 002 - always means "mismatch"
// Everyone in the ecosystem knows what these mean!
Sequence Categories
Input/Data Validation (001-010)
use *;
MISSING // 001 - Required data not provided
MISMATCH // 002 - Type or length mismatch
INVALID // 003 - Validation check failed
OVERFLOW // 004 - Value too large
UNDERFLOW // 005 - Value too small
OUT_OF_BOUNDS // 006 - Outside valid range
DUPLICATE // 007 - Duplicate entry
DENIED // 008 - Permission denied
UNSUPPORTED // 009 - Feature not supported
DEPRECATED // 010 - Feature deprecated
State/Lifecycle (011-020)
use *;
UNINITIALIZED // 011 - Not initialized
ALREADY_INIT // 012 - Already initialized
CLOSED // 013 - Resource closed
CANCELLED // 014 - Operation cancelled
IN_PROGRESS // 015 - Already in progress
NOT_READY // 016 - Not ready
TIMEOUT // 017 - Operation timed out
STALE // 018 - Resource stale/expired
// 019-020 reserved for future use
Resource/Storage (021-030)
Includes network operations per WDP-6 ยง4.3.
use *;
NOT_FOUND // 021 - Resource not found
ALREADY_EXISTS // 022 - Resource already exists
CONFLICT // 023 - Version/data conflict
LOCKED // 024 - Resource locked
CORRUPTED // 025 - Data corrupted
EXHAUSTED // 026 - Resource exhausted
UNAVAILABLE // 027 - Service temporarily unavailable (network)
UNREACHABLE // 028 - Network connectivity failure
DISCONNECTED // 029 - Connection lost
// 030 reserved for future use
Success/Completion (998-999)
use *;
PARTIAL // 998 - Partial success
COMPLETE // 999 - Full success
Three Ways to Use This Library
๐ข Approach 1: Pure Constants (Default)
Perfect for: Lightweight projects, no_std, minimal dependencies
use *;
const ERROR_CODE: u16 = MISSING; // Just a number
const ANOTHER: u16 = NOT_FOUND;
Dependencies: Zero
Binary size: Minimal
Features: Basic constants only
๐ต Approach 2: With Metadata (Runtime Documentation)
Perfect for: Tools, CLIs, error reporting systems
[]
= { = "0.2", = ["metadata"] }
use ;
// Query metadata at runtime
if let Some = get
// Get by name
let meta = get_by_name.unwrap;
// Browse all sequences
for seq in ALL_SEQUENCES.iter
Dependencies: Zero (still!)
Binary size: Includes metadata strings
Features: Runtime documentation, lookup functions
๐ฃ Approach 3: With Macros (Full Ecosystem Integration)
Perfect for: waddling-errors projects, compile-time validation
[]
= { = "0.2", = ["macros"] }
= "0.6"
use ;
// Set up paths for macro validation
setup!
// Use with compile-time validation!
diag!
Dependencies: waddling-errors, waddling-errors-macros
Binary size: Comparable to metadata (macros expand at compile time)
Features: Compile-time validation, auto-registration, type safety
Comparison Table
| Feature | Pure Constants | Metadata | Macros |
|---|---|---|---|
| Dependencies | Zero | Zero | waddling-errors |
| no_std | โ Yes | โ Yes | โ Yes |
| Runtime Metadata | โ No | โ Yes | โ Yes |
| Compile-time Validation | โ No | โ No | โ Yes |
| Auto-registration | โ No | โ No | โ Optional |
| Doc Generation | โ No | โ No | โ Yes (with doc-gen) |
| Best For | Minimal deps | Tools/CLIs | Full ecosystem |
With Metadata Feature
Enable the metadata feature to get rich documentation at runtime:
[]
= { = "0.2", = ["metadata"] }
use metadata;
// Get documentation for a sequence by number
let meta = get.unwrap;
println!;
// Output: MISSING: Required data not provided
// Get by name (case-insensitive)
let meta2 = get_by_name.unwrap;
println!;
// Browse by category
let validation_sequences = by_category;
for seq in validation_sequences
The metadata includes:
- Sequence number and name
- Description from WDP-6
- When to use this sequence
- Category and range
- Typical severity level
Documentation Generation
Generate comprehensive HTML and JSON documentation with the doc-gen feature:
[]
= { = "0.2", = ["doc-gen"] }
use generate_docs;
This creates:
- ๐ Waddling_Standard_Sequences-pub.html - Public documentation
- ๐ Waddling_Standard_Sequences-dev.html - Developer documentation
- ๐ Waddling_Standard_Sequences-int.html - Internal documentation
- ๐ JSON exports - For custom tooling and integrations
Run the example:
Examples
Check out the examples/ directory:
- basic.rs - Simple usage with constants
- metadata.rs - Querying metadata at runtime
- with_macros.rs - Full ecosystem integration with macros
- generate_docs.rs - Generate HTML/JSON documentation
Project-Specific Sequences
Sequences 031-897 are available for project-specific use per WDP-6!
// Your custom sequences (unreserved range)
const MY_CUSTOM_ERROR: u16 = 031;
const ANOTHER_ERROR: u16 = 050;
const DOMAIN_SPECIFIC: u16 = 101;
const BUSINESS_LOGIC: u16 = 250;
// Reserved sequences 001-030, 998-999 follow WDP-6 conventions
Usage with waddling-errors
waddling-sequences integrates seamlessly with the waddling-errors ecosystem:
use Code;
use *;
// Use standard sequences in your error codes
const TYPE_ERROR: Code = new; // 003
const USER_NOT_FOUND: Code = new; // 021
Or with macros for compile-time validation:
use diag;
use *;
diag!
Why Standard Sequences?
Before (Inconsistent)
// Project A
const ERR_MISSING: u16 = 001; // "missing"
const ERR_NOTFOUND: u16 = 002; // "not found"
// Project B
const ERR_NOTFOUND: u16 = 001; // "not found"
const ERR_MISSING: u16 = 005; // "missing"
โ Same concept, different numbers across projects!
After (Consistent with WDP-6)
// Project A
use MISSING; // 001
use NOT_FOUND; // 021
// Project B
use MISSING; // 001
use NOT_FOUND; // 021
โ Same number, same meaning, everywhere!
WDP-6 Compliance
This crate implements WDP Part 6: Sequence Conventions:
- โ Reserved sequences (001-030) follow standard semantics
- โ Project-specific range (031-897) available for custom use
- โ Success sequences (998-999) for completion states
- โ
Consistent naming with underscores (e.g.,
NOT_FOUND,IN_PROGRESS) - โ Comprehensive metadata aligned with specification
No-std Support
Works in no-std environments:
use *;
const ERR: u16 = MISSING; // Works everywhere!
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md.
Made with waddles by ๐ฆ