ferrous-di 0.2.0

Type-safe, performant dependency injection for Rust, inspired by Microsoft.Extensions.DependencyInjection
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
# API Stability Guarantees

## Overview

This document defines the API stability guarantees for ferrous-di, providing clear expectations for users about what changes can be expected across different types of releases. These guarantees form the foundation of our semantic versioning policy and release engineering practices.

## Stability Commitment

### Core Promise
ferrous-di commits to providing **predictable API evolution** with **clear migration paths** for necessary changes. Users should be able to upgrade with confidence, knowing exactly what to expect from each release type.

### Rust Ecosystem Alignment
Our stability guarantees align with Rust ecosystem best practices:
- Follow semantic versioning strictly
- Maintain source compatibility within major versions
- Provide deprecation warnings before removal
- Document all breaking changes comprehensively

## API Stability Tiers

### 🔒 Tier 1: Stable API (Ironclad Guarantees)

#### Core Types and Traits
```rust
// These APIs have the strongest stability guarantees
pub trait Resolver { }
pub trait ResolverCore { }
pub struct ServiceCollection { }
pub struct ServiceProvider { }
pub struct Scope { }
pub enum DiError { }
pub type DiResult<T> = Result<T, DiError>;
```

#### Stability Promise
- **No breaking changes** within major version
- **Minimum 12 months** deprecation period before removal
- **Extensive migration support** for major version changes
- **Backwards compatibility** maintained at all costs

#### Change Policy
- **PATCH**: Bug fixes only, no API changes
- **MINOR**: Additive changes only (new methods with defaults)
- **MAJOR**: Breaking changes allowed with comprehensive migration

### ðŸŸĄ Tier 2: Evolving API (Strong Guarantees)

#### Advanced Features
```rust
// These APIs have strong but flexible guarantees
pub mod async_factories { }
pub mod decorators { }
pub mod observers { }
pub mod graph_export { }
pub trait AsyncFactory<T> { }
pub trait ServiceDecorator { }
```

#### Stability Promise
- **Careful evolution** within major versions
- **6 months minimum** deprecation period
- **Clear migration paths** for changes
- **Additive changes preferred** over breaking changes

#### Change Policy
- **PATCH**: Bug fixes, minor behavior corrections
- **MINOR**: New features, minor breaking changes if well-justified
- **MAJOR**: Significant API redesign allowed

### 🟠 Tier 3: Experimental API (Limited Guarantees)

#### Experimental Features
```rust
// These APIs may change with less notice
#[cfg(feature = "experimental")]
pub mod experimental { }

#[doc(hidden)]
pub mod internal { }

// APIs marked as unstable
#[unstable(feature = "advanced_features")]
pub fn experimental_method() { }
```

#### Stability Promise
- **May change** in minor versions with clear documentation
- **Minimal deprecation** period (1 minor version)
- **Clear experimental marking** in documentation
- **Opt-in usage** through feature flags or explicit imports

#### Change Policy
- **PATCH**: Bug fixes, small improvements
- **MINOR**: API changes allowed with documentation
- **MAJOR**: Complete redesign or removal allowed

## Compatibility Guarantees

### Source Compatibility

#### Within Major Versions (X.Y.Z → X.Y+n.Z)
```rust
// This code should continue to compile across minor versions
let mut services = ServiceCollection::new();
services.add_singleton(MyService::new());
let provider = services.build();
let service = provider.get_required::<MyService>();
```

**Guarantees:**
- Code that compiles with version X.Y.Z compiles with X.Y+n.Z
- Existing method signatures remain unchanged
- Existing behavior remains consistent (except for bug fixes)

#### Across Major Versions (X.Y.Z → X+1.Y.Z)
**No guarantees** - breaking changes allowed with:
- Comprehensive migration documentation
- Automated migration tools when possible
- Clear timeline and rationale

### Behavioral Compatibility

#### Documented Behavior
```rust
/// Resolves a service of type T.
/// 
/// # Behavior Guarantee
/// This method will always return the same instance for Singleton services
/// within the same ServiceProvider instance.
/// 
/// # Errors
/// Returns DiError::ServiceNotFound if no service of type T is registered.
pub fn get_required<T>(&self) -> DiResult<Arc<T>> { }
```

**Guarantees:**
- Documented behavior remains consistent within major versions
- Error conditions remain the same unless explicitly documented
- Performance characteristics maintained within reasonable bounds

#### Undocumented Behavior
**No guarantees** - implementation details may change in any release:
- Internal data structures
- Memory layout
- Specific error messages (beyond documented types)
- Performance characteristics (unless documented)

### ABI Compatibility

#### Rust ABI Limitations
Rust does not provide stable ABI, therefore:
- **No ABI compatibility** guaranteed across any releases
- **Recompilation required** for all dependency updates
- **Dynamic linking** not supported or recommended

#### Recommendations
- Pin specific versions in production: `ferrous-di = "=1.2.3"`
- Use compatible version ranges: `ferrous-di = "1.2"`
- Test thoroughly when updating versions

## MSRV (Minimum Supported Rust Version) Policy

### Current MSRV: Rust 1.70.0

#### MSRV Update Policy
- **Conservative approach**: 6-month lag behind latest stable
- **Patch releases**: Never increase MSRV
- **Minor releases**: May increase within same Rust minor version (1.70.0 → 1.70.8)
- **Major releases**: May increase to newer Rust minor version (1.70.x → 1.75.x)

#### MSRV Change Communication
```toml
# Clear documentation in Cargo.toml
[package]
rust-version = "1.70.0"  # Enforced MSRV

# Clear documentation in README
## Minimum Supported Rust Version (MSRV)
This crate requires Rust 1.70.0 or newer.
```

### MSRV Testing
- CI tests against MSRV and latest stable
- MSRV bumps require strong justification
- Community notification for MSRV changes

## Feature Flag Stability

### Feature Flag Categories

#### Stable Features
```toml
[features]
default = ["std"]
std = []  # Stable feature, safe for production
async = ["tokio"]  # Stable feature, well-tested
```

**Guarantees:**
- Feature flags themselves won't be removed within major versions
- APIs behind stable features follow Tier 1 or Tier 2 guarantees
- Feature combinations are tested and supported

#### Experimental Features
```toml
[features]
experimental = []  # May change or be removed
unstable-async = []  # No stability guarantees
```

**Guarantees:**
- May be removed in minor versions with clear notice
- APIs may change significantly
- Not recommended for production use

### Feature Flag Evolution
- **Adding features**: Always safe in minor releases
- **Changing feature behavior**: Follows same rules as API changes
- **Removing features**: Only in major releases (stable) or minor releases (experimental)

## Error Handling Stability

### Error Type Guarantees

#### Stable Error Types
```rust
#[derive(Debug, Clone, PartialEq)]
pub enum DiError {
    ServiceNotFound(String),
    CircularDependency(Vec<String>),
    LifetimeViolation(String),
    // Adding new variants is non-breaking
}
```

**Guarantees:**
- Existing error variants won't be removed within major versions
- Error variant data may be enhanced (non-breaking)
- New error variants may be added (non-breaking)
- Error messages may improve (not guaranteed to be stable)

#### Error Compatibility
```rust
// This pattern should continue to work
match provider.get::<MyService>() {
    Ok(service) => { /* use service */ }
    Err(DiError::ServiceNotFound(_)) => { /* handle missing service */ }
    Err(other) => { /* handle other errors */ }
}
```

## Performance Guarantees

### Performance Characteristics

#### Algorithmic Complexity
Current documented complexities that won't regress within major versions:
- **Service resolution**: O(1) for singletons, O(log n) for scoped
- **Registration**: O(1) amortized
- **Scope creation**: O(1)

#### Performance Regression Policy
- **Significant regressions** (>25%) are considered breaking changes
- **Minor optimizations** allowed in any release
- **Benchmark requirements** for performance-sensitive changes

### Benchmark Stability
```rust
// These benchmarks define our performance contracts
#[bench]
fn singleton_resolution_performance() {
    // Must complete in <100ns on reference hardware
}

#[bench]
fn scope_creation_performance() {
    // Must complete in <1Ξs on reference hardware
}
```

## Documentation Stability

### API Documentation
- **Method signatures** in docs must match actual implementation
- **Examples** must compile and work with current version
- **Behavior descriptions** are part of stability contract

### Migration Documentation
- **Migration guides** maintained for all major version transitions
- **Deprecation notices** provide clear alternatives
- **Breaking change documentation** includes timeline and rationale

## Testing Stability Guarantees

### Public API Testing
```rust
#[test]
fn api_stability_test() {
    // These tests verify API stability promises
    let services = ServiceCollection::new();
    // This API must remain stable within major version
    assert!(services.add_singleton(String::from("test")).is_ok());
}
```

### Integration Testing
- Tests that verify compatibility with common usage patterns
- Tests that ensure migration paths work correctly
- Tests that validate performance characteristics

## Ecosystem Compatibility

### Popular Crate Integration
We maintain compatibility testing with popular crates in the ecosystem:
- **tokio**: Async runtime integration
- **serde**: Serialization support
- **tracing**: Logging and diagnostics

### Framework Integration
Stability guarantees for integration patterns:
- **Web frameworks**: Axum, Actix, Warp integration patterns
- **CLI tools**: Integration with clap and similar
- **Database libraries**: Connection pool management patterns

## Violating Stability Guarantees

### Emergency Exceptions
Stability guarantees may be violated only for:
- **Critical security vulnerabilities** that can't be fixed compatibly
- **Memory safety issues** that pose immediate risk
- **Data corruption bugs** that can't be fixed without breaking changes

### Exception Process
1. **Security review** confirms necessity
2. **Community notification** with emergency timeline
3. **Rapid patch release** with clear documentation
4. **Follow-up** with better long-term solution

### Exception Communication
```markdown
# SECURITY RELEASE 1.2.4

## Emergency Breaking Change

This release contains a security fix that requires a breaking change.
The fix addresses CVE-XXXX-XXXX which could lead to memory safety violations.

### Breaking Change
- Method `unsafe_method()` has been removed immediately
- Use `safe_alternative()` instead

### Migration
// Before (vulnerable)
unsafe_method(data);

// After (secure)
safe_alternative(data)?;
```

## Stability Validation

### Automated Checks
- **API diff validation** in CI prevents accidental breaking changes
- **Semver-check** tool validates version increments
- **Documentation tests** ensure examples remain valid

### Manual Review Process
- **API review board** for significant changes
- **Community feedback** period for major changes
- **Breaking change justification** required

### Tooling
```bash
# Tools used to validate stability
cargo semver-checks
cargo doc --all-features
cargo test --all-features
cargo audit
```

## Community Communication

### Stability Promise Communication
- **Clear documentation** in README and docs
- **Stability badges** indicating API maturity
- **Change notification** through multiple channels

### Feedback Channels
- **GitHub issues** for stability concerns
- **Community forums** for discussion
- **Direct contact** for security issues

## Future Evolution

### Planned Improvements
- **Enhanced performance** guarantees with more detailed metrics
- **ABI stability** exploration for specific use cases
- **Formal verification** of critical stability properties

### Policy Updates
This stability policy itself may evolve:
- Annual review of policy effectiveness
- Community feedback incorporation
- Ecosystem best practice alignment

---

## Quick Reference

### Stability Tiers
- **🔒 Tier 1**: Core APIs - Ironclad stability guarantees
- **ðŸŸĄ Tier 2**: Advanced APIs - Strong but flexible guarantees  
- **🟠 Tier 3**: Experimental APIs - Limited guarantees

### Version Impact
- **PATCH (X.Y.Z+1)**: Bug fixes only, no API changes
- **MINOR (X.Y+1.0)**: Additive changes, strong backwards compatibility
- **MAJOR (X+1.0.0)**: Breaking changes allowed with migration support

### MSRV Policy
- **Conservative**: 6-month lag behind Rust stable
- **Patch**: Never increases MSRV
- **Minor**: May increase within Rust minor version
- **Major**: May increase to newer Rust minor version

These stability guarantees provide the foundation for reliable, predictable API evolution while enabling necessary improvements and innovations in ferrous-di.