waddling-sequences 0.2.0

Standard WDP-6 compliant sequence constants for consistent diagnostic codes across the Waddling ecosystem
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
# ๐Ÿฆ† waddling-sequences


**Standard error sequence definitions for the Waddling ecosystem**

[![Crates.io](https://img.shields.io/crates/v/waddling-sequences.svg)](https://crates.io/crates/waddling-sequences)
[![Docs.rs](https://docs.rs/waddling-sequences/badge.svg)](https://docs.rs/waddling-sequences)
[![License](https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg)](LICENSE-MIT)

---

## 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)](https://github.com/waddling/wdp-specs/blob/main/6-SEQUENCE-CONVENTIONS.md)

## 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 (`metadata` feature)
- ๐ŸŒ **Optional doc generation** - Generate HTML/JSON docs (`doc-gen` feature)
- ๐Ÿ”ง **Optional macros** - Full waddling-errors ecosystem integration (`macros` feature)

## Three Ways to Use


### 1. Pure Constants (Default - Zero Dependencies)


```rust
use waddling_sequences::prelude::*;

// Just numbers - minimal, no_std compatible
const MY_ERROR: u16 = MISSING;  // 001
const OTHER_ERROR: u16 = NOT_FOUND;  // 021
```

### 2. With Metadata (Runtime Documentation)


```toml
[dependencies]
waddling-sequences = { version = "0.2", features = ["metadata"] }
```

```rust
use waddling_sequences::{prelude::*, metadata};

// Query metadata at runtime
if let Some(info) = metadata::get(MISSING) {
    println!("{}: {}", info.name, info.docs);
    println!("Typical severity: {}", info.typical_severity);
}
```

### 3. With Macros (Full Ecosystem Integration)


```toml
[dependencies]
waddling-sequences = { version = "0.2", features = ["macros"] }
waddling-errors-macros = "0.6"
```

```rust
use waddling_errors_macros::{setup, diag};

setup! {
    sequences = waddling_sequences::macros::sequences,
    // ... your components and primaries
}

diag! {
    strict(sequence),  // Compile-time validation!
    
    E.Auth.Token.MISSING: {
        message: "JWT token missing",
        // MISSING validated at compile time!
    },
}
```

## Quick Start


```rust
use waddling_sequences::prelude::*;

// 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)

```rust
use waddling_sequences::input_validation::*;

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)

```rust
use waddling_sequences::state_lifecycle::*;

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.

```rust
use waddling_sequences::resource_storage::*;

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)

```rust
use waddling_sequences::success::*;

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

```rust
use waddling_sequences::prelude::*;

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

```toml
[dependencies]
waddling-sequences = { version = "0.2", features = ["metadata"] }
```

```rust
use waddling_sequences::{prelude::*, metadata};

// Query metadata at runtime
if let Some(info) = metadata::get(MISSING) {
    println!("{}: {}", info.name, info.docs);
    println!("Severity: {}", info.typical_severity);
    println!("When to use: {}", info.when_to_use);
}

// Get by name
let meta = metadata::get_by_name("NOT_FOUND").unwrap();

// Browse all sequences
for seq in metadata::ALL_SEQUENCES.iter() {
    println!("{:03} - {}", seq.number, seq.name);
}
```

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

```toml
[dependencies]
waddling-sequences = { version = "0.2", features = ["macros"] }
waddling-errors-macros = "0.6"
```

```rust
use waddling_errors_macros::{setup, diag};

// Set up paths for macro validation
setup! {
    sequences = waddling_sequences::macros::sequences,
    components = crate::components,
    primaries = crate::primaries,
}

// Use with compile-time validation!
diag! {
    strict(sequence),  // Validates MISSING exists at compile time
    
    E.Auth.Token.MISSING: {
        message: "JWT token missing",
        description: "Authorization header is missing required JWT token",
        hints: ["Add Authorization: Bearer <token> header"],
        tags: ["authentication", "jwt"],
    },
}
```

**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:

```toml
[dependencies]
waddling-sequences = { version = "0.2", features = ["metadata"] }
```

```rust
use waddling_sequences::metadata;

// Get documentation for a sequence by number
let meta = metadata::get(1).unwrap();
println!("{}: {}", meta.name, meta.docs);
// Output: MISSING: Required data not provided

// Get by name (case-insensitive)
let meta2 = metadata::get_by_name("TIMEOUT").unwrap();
println!("Sequence {}: {}", meta2.number, meta2.when_to_use);

// Browse by category
let validation_sequences = metadata::by_category("Input/Data Validation");
for seq in validation_sequences {
    println!("{:03} {}: {}", seq.number, seq.name, seq.docs);
}
```

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:

```toml
[dependencies]
waddling-sequences = { version = "0.2", features = ["doc-gen"] }
```

```rust
use waddling_sequences::docgen::generate_docs;

fn main() {
    // Generates role-based documentation (pub, dev, int)
    generate_docs("target/doc").unwrap();
    println!("๐Ÿ“š Documentation generated!");
}
```

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:
```bash
cargo run --example generate_docs --features doc-gen
```

## Examples


Check out the [examples/](examples/) directory:

- **[basic.rs]examples/basic.rs** - Simple usage with constants
- **[metadata.rs]examples/metadata.rs** - Querying metadata at runtime
- **[with_macros.rs]examples/with_macros.rs** - Full ecosystem integration with macros
- **[generate_docs.rs]examples/generate_docs.rs** - Generate HTML/JSON documentation

## Project-Specific Sequences


Sequences **031-897** are **available for project-specific use** per WDP-6!

```rust
// 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:

```rust
use waddling_errors::Code;
use waddling_sequences::prelude::*;

// Use standard sequences in your error codes
const TYPE_ERROR: Code = Code::new("E", "TYPES", "CHECK", INVALID);  // 003
const USER_NOT_FOUND: Code = Code::new("E", "USER", "LOOKUP", NOT_FOUND);  // 021
```

Or with macros for compile-time validation:

```rust
use waddling_errors_macros::diag;
use waddling_sequences::macros::sequences::*;

diag! {
    strict(sequence),  // Validates sequences at compile time!
    
    E.User.Lookup.NOT_FOUND: {
        message: "User not found",
        // NOT_FOUND is validated to exist
    },
}
```

## Why Standard Sequences?


### Before (Inconsistent)

```rust
// 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)

```rust
// Project A
use waddling_sequences::core::MISSING;      // 001
use waddling_sequences::resource::NOT_FOUND; // 021

// Project B
use waddling_sequences::core::MISSING;      // 001
use waddling_sequences::resource::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:
```rust
#![no_std]

use waddling_sequences::core::*;

const ERR: u16 = MISSING;  // Works everywhere!
```

## License


Licensed under either of:

- Apache License, Version 2.0 ([LICENSE-APACHE]LICENSE-APACHE)
- MIT license ([LICENSE-MIT]LICENSE-MIT)

at your option.

## Contributing


Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md).

---

**Made with waddles by ๐Ÿฆ†**