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
//! Migrating an application from anyhow to rootcause
//!
//! This example shows how to gradually adopt rootcause in an existing
//! anyhow-based codebase. We'll migrate a small application that uses
//! a key-value store with metrics collection.
//!
//! # Migration Strategies
//!
//! You can migrate in any order that makes sense for your codebase:
//!
//! - **Top-down** (application first): Use rootcause features immediately in
//! your business logic. Call anyhow dependencies with `.into_rootcause()`.
//!
//! - **Bottom-up** (libraries first): Adopt rootcause internally while keeping
//! anyhow-compatible public APIs using `.into_anyhow()`.
//!
//! - **Middle-out**: Not recommended - requires conversions in both directions.
//!
//! **Which to choose?** Start where you'll get the most value from rootcause's
//! features, and prefer loosely-connected code (leaf libraries or top-level
//! binaries). For most users, **starting top-down** is easiest - you get
//! immediate benefits and only need `.into_rootcause()` conversions.
//!
//! # This Example's Approach
//!
//! We demonstrate a **combination approach**: start top-down with the
//! application, then gradually convert dependencies. This is realistic when
//! you control all the code but want to be cautious about breaking changes.
//!
//! The example treats each component as if it came from a separate crate:
//! - `metrics`: A metrics collection library (pretend you depend on this)
//! - `kv_store`: A key-value store (pretend you depend on this too)
//! - Your application: The code you're migrating
//!
//! # Migration Stages
//!
//! Each stage is in its own file so you can open them side-by-side for
//! comparison:
//!
//! 1. **Stage 1** (`stage1.rs`): Everything uses anyhow (starting point)
//! 2. **Stage 2** (`stage2.rs`): Application converted to rootcause
//! 3. **Stage 3** (`stage3.rs`): Metrics library converted internally
//! 4. **Stage 4** (`stage4.rs`): KV store converted internally
//! 5. **Stage 5** (`stage5.rs`): Full migration complete (breaking change to
//! public APIs)
// =============================================================================
// Stage 1: Everything uses anyhow
// =============================================================================
// =============================================================================
// Stage 2: Application converted to rootcause
// =============================================================================
// =============================================================================
// Stage 3: Metrics library converted internally
// =============================================================================
// =============================================================================
// Stage 4: KV store converted internally
// =============================================================================
// =============================================================================
// Stage 5: Full migration complete
// =============================================================================
// =============================================================================
// Main - run all stages
// =============================================================================