conventions/
conventions.rs

1use waddling_errors::prelude::*;
2
3// # Sequence Conventions Example
4//
5// This example demonstrates the recommended sequence conventions
6// for the Waddling ecosystem.
7//
8// Run with: `cargo run --example conventions`
9
10fn main() {
11    println!("🦆 Waddling Error Sequence Conventions Demo\n");
12    println!("═══════════════════════════════════════════════════\n");
13
14    // ========================================================================
15    // CONVENTIONAL SEQUENCES (001-030)
16    // ========================================================================
17
18    println!("✅ CONVENTIONAL SEQUENCES (Recommended)\n");
19
20    // Core Errors (001-010)
21    println!("Core Errors (001-010):");
22
23    const ERR_MISSING: Code = error("CRYPTO", "SALT", 1);
24    println!(
25        "  {} - .001 = MISSING (required item not provided)",
26        ERR_MISSING.code()
27    );
28
29    const ERR_MISMATCH: Code = error("CRYPTO", "LENGTH", 2);
30    println!(
31        "  {} - .002 = MISMATCH (values don't match)",
32        ERR_MISMATCH.code()
33    );
34
35    const ERR_INVALID: Code = error("PATTERN", "REGEX", 3);
36    println!(
37        "  {} - .003 = INVALID (format/validation failed)",
38        ERR_INVALID.code()
39    );
40
41    const ERR_OVERFLOW: Code = error("BUFFER", "SIZE", 4);
42    println!(
43        "  {} - .004 = OVERFLOW (value too large)",
44        ERR_OVERFLOW.code()
45    );
46
47    const ERR_TIMEOUT: Code = blocked("NETWORK", "CONN", 7);
48    println!(
49        "  {} - .007 = TIMEOUT (operation timed out)",
50        ERR_TIMEOUT.code()
51    );
52
53    const WARN_DEPRECATED: Code = warning("API", "FUNC", 10);
54    println!(
55        "  {} - .010 = DEPRECATED (feature deprecated)\n",
56        WARN_DEPRECATED.code()
57    );
58
59    // State/Lifecycle Errors (011-020)
60    println!("State/Lifecycle Errors (011-020):");
61
62    const ERR_UNINITIALIZED: Code = error("ENGINE", "STATE", 11);
63    println!(
64        "  {} - .011 = UNINITIALIZED (not initialized)",
65        ERR_UNINITIALIZED.code()
66    );
67
68    const ERR_ALREADYINIT: Code = error("ENGINE", "STATE", 12);
69    println!(
70        "  {} - .012 = ALREADYINIT (already initialized)",
71        ERR_ALREADYINIT.code()
72    );
73
74    const ERR_CLOSED: Code = error("STREAM", "STATE", 13);
75    println!("  {} - .013 = CLOSED (resource closed)", ERR_CLOSED.code());
76
77    const BLOCKED_INPROGRESS: Code = blocked("TASK", "STATE", 15);
78    println!(
79        "  {} - .015 = INPROGRESS (operation in progress)\n",
80        BLOCKED_INPROGRESS.code()
81    );
82
83    // Resource Errors (021-030)
84    println!("Resource Errors (021-030):");
85
86    const ERR_NOTFOUND: Code = error("DATA", "KEY", 21);
87    println!(
88        "  {} - .021 = NOTFOUND (resource not found)",
89        ERR_NOTFOUND.code()
90    );
91
92    const ERR_ALREADYEXISTS: Code = error("FILE", "CREATE", 22);
93    println!(
94        "  {} - .022 = ALREADYEXISTS (already exists)",
95        ERR_ALREADYEXISTS.code()
96    );
97
98    const CRIT_EXHAUSTED: Code = critical("MEM", "ALLOC", 23);
99    println!(
100        "  {} - .023 = EXHAUSTED (resource exhausted)",
101        CRIT_EXHAUSTED.code()
102    );
103
104    const BLOCKED_LOCKED: Code = blocked("THREAD", "MUTEX", 24);
105    println!(
106        "  {} - .024 = LOCKED (resource locked)",
107        BLOCKED_LOCKED.code()
108    );
109
110    const CRIT_CORRUPTED: Code = critical("CRYPTO", "MAC", 25);
111    println!(
112        "  {} - .025 = CORRUPTED (data corrupted)\n",
113        CRIT_CORRUPTED.code()
114    );
115
116    // ========================================================================
117    // PROJECT-SPECIFIC SEQUENCES (031-897)
118    // ========================================================================
119
120    println!("═══════════════════════════════════════════════════\n");
121    println!("✨ PROJECT-SPECIFIC SEQUENCES (Free Use)\n");
122    println!("Domain-Specific Range (031-897):");
123
124    const ERR_HMAC_COMPUTE: Code = error("CRYPTO", "HMAC", 31);
125    println!(
126        "  {} - Domain-specific (HMAC computation)",
127        ERR_HMAC_COMPUTE.code()
128    );
129
130    const ERR_PATTERN_COMPLEX: Code = warning("PATTERN", "PERF", 45);
131    println!(
132        "  {} - Domain-specific (pattern complexity)",
133        ERR_PATTERN_COMPLEX.code()
134    );
135
136    const ERR_AST_MALFORMED: Code = error("parser", "AST", 51);
137    println!(
138        "  {} - Domain-specific (AST structure)\n",
139        ERR_AST_MALFORMED.code()
140    );
141
142    // ========================================================================
143    // SUCCESS SEQUENCES (998-999)
144    // ========================================================================
145
146    println!("═══════════════════════════════════════════════════\n");
147    println!("🎉 SUCCESS SEQUENCES (Positive Outcomes)\n");
148    println!("Success Range (998-999):");
149
150    const SUCCESS_PARTIAL: Code = success("BUILD", "RESULT", 998);
151    println!(
152        "  {} - .998 = PARTIAL (partial success)",
153        SUCCESS_PARTIAL.code()
154    );
155
156    const SUCCESS_COMPLETE: Code = success("REDACT", "DONE", 999);
157    println!(
158        "  {} - .999 = COMPLETE (full completion)",
159        SUCCESS_COMPLETE.code()
160    );
161
162    const COMPLETE_COMPILE: Code = completed("BUILD", "DONE", 999);
163    println!(
164        "  {} - .999 = COMPLETE (compilation finished)\n",
165        COMPLETE_COMPILE.code()
166    );
167
168    // ========================================================================
169    // CROSS-PROJECT CONSISTENCY
170    // ========================================================================
171
172    println!("═══════════════════════════════════════════════════\n");
173    println!("🌐 CROSS-PROJECT CONSISTENCY\n");
174    println!("Same semantic meaning across different projects:\n");
175
176    // "Missing" errors across different projects
177    const DUCOY_MISSING: Code = error("CRYPTO", "SALT", 1);
178    println!("Ducoy:      {} (.001 = MISSING)", DUCOY_MISSING.code());
179
180    const QUACKPATCH_MISSING: Code = error("parser", "TOKEN", 1);
181    println!("QuackPatch: {} (.001 = MISSING)", QUACKPATCH_MISSING.code());
182
183    const STATEQUACK_MISSING: Code = error("STATE", "KEY", 1);
184    println!(
185        "StateQuack: {} (.001 = MISSING)\n",
186        STATEQUACK_MISSING.code()
187    );
188
189    println!("👆 Notice: .001 ALWAYS means \"missing\" - instant recognition!\n");
190
191    // ========================================================================
192    // BENEFITS
193    // ========================================================================
194
195    println!("═══════════════════════════════════════════════════\n");
196    println!("💡 BENEFITS OF CONVENTIONS\n");
197    println!("  ✅ Instant Recognition");
198    println!("     .001 anywhere → \"missing\" error\n");
199    println!("  ✅ Cross-Project Learning");
200    println!("     Understand Ducoy → understand all Waddling projects\n");
201    println!("  ✅ Searchability");
202    println!("     Search .001 finds all \"missing\" errors ecosystem-wide\n");
203    println!("  ✅ Predictability");
204    println!("     Users can guess meanings from sequences alone\n");
205    println!("  ✅ Documentation");
206    println!("     Document patterns once, reference everywhere\n");
207
208    println!("═══════════════════════════════════════════════════\n");
209    println!("📚 Full documentation: docs/SEQUENCE-CONVENTIONS.md");
210    println!("🔧 Enforcement strategies: docs/ENFORCEMENT.md\n");
211}