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
//! API Stability Guarantees for scirs2-datasets
//!
//! This module defines the API stability levels and compatibility guarantees
//! for the scirs2-datasets crate. It provides documentation and markers for
//! different stability levels of the public API.
/// API stability levels for different components of the crate
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum StabilityLevel {
/// Stable API - Guaranteed backward compatibility within major versions
///
/// These APIs will not change in breaking ways within the same major version.
/// New functionality may be added with minor version bumps, but existing
/// functionality will remain backward compatible.
Stable,
/// Experimental API - Subject to change in minor versions
///
/// These APIs are considered experimental and may change or be removed
/// in future minor versions. Use with caution in production code.
Experimental,
/// Internal API - Not part of the public API
///
/// These APIs are for internal use only and may change without notice.
/// They should not be used by external code.
Internal,
}
/// Trait to mark API stability level for types and functions
pub trait ApiStability {
/// The stability level of this API component
const STABILITY: StabilityLevel;
/// Optional version when this API was introduced
const INTRODUCED_IN: Option<&'static str> = None;
/// Optional version when this API was stabilized (if applicable)
const STABILIZED_IN: Option<&'static str> = None;
/// Optional deprecation information
const DEPRECATED_IN: Option<&'static str> = None;
}
/// Macro to easily annotate APIs with stability information
#[macro_export]
macro_rules! api_stability {
(stable, $item:item) => {
#[doc = " **API Stability: Stable** - Guaranteed backward compatibility within major versions"]
$item
};
(experimental, $item:item) => {
#[doc = " **API Stability: Experimental** - Subject to change in minor versions"]
$item
};
(internal, $item:item) => {
#[doc = " **API Stability: Internal** - Not part of the public API"]
$item
};
}
/// Current API version and compatibility matrix
pub struct ApiVersion;
impl ApiVersion {
/// Current API version
pub const CURRENT: &'static str = "0.1.0";
/// Minimum supported API version for backward compatibility
pub const MIN_SUPPORTED: &'static str = "0.1.0";
/// Next planned API version
pub const NEXT_PLANNED: &'static str = "0.2.0";
}
/// API compatibility guarantees
///
/// This structure documents the compatibility guarantees for different
/// components of the scirs2-datasets crate.
pub struct CompatibilityGuarantees;
impl CompatibilityGuarantees {
/// Core dataset types and basic operations
///
/// These are considered stable and will maintain backward compatibility:
/// - `Dataset` struct and its public methods
/// - Basic dataset loading functions (`load_iris`, `load_boston`, etc.)
/// - Core data generation functions (`make_classification`, `make_regression`, etc.)
/// - Cross-validation utilities
/// - Basic dataset manipulation functions
pub const CORE_API_STABLE: &'static str = "
The following APIs are considered stable and will maintain backward compatibility:
- Dataset struct and its public methods (n_samples, n_features, etc.)
- Toy dataset loaders (load_iris, load_boston, load_breast_cancer, etc.)
- Core data generators (make_classification, make_regression, make_blobs, etc.)
- Cross-validation utilities (k_fold_split, stratified_k_fold_split, etc.)
- Basic dataset utilities (train_test_split, normalize_features, etc.)
- Error types and Result definitions
";
/// Advanced features that are experimental
///
/// These features may change in minor versions:
/// - GPU acceleration APIs
/// - Cloud storage integration
/// - Distributed processing
/// - Advanced ML pipeline integration
/// - Domain-specific datasets
pub const EXPERIMENTAL_API: &'static str = "
The following APIs are experimental and may change in minor versions:
- GPU acceleration (gpu module)
- Cloud storage integration (cloud module)
- Distributed processing (distributed module)
- Advanced ML pipeline features (ml_integration advanced features)
- Domain-specific datasets (domain_specific module)
- Streaming dataset processing (streaming module)
- Advanced data generators (advanced_generators module)
";
/// Internal APIs that may change without notice
///
/// These are not part of the public API:
/// - Cache implementation details
/// - Internal data structures
/// - Private utility functions
pub const INTERNAL_API: &'static str = "
The following APIs are internal and may change without notice:
- Cache implementation details
- Internal registry structures
- Private utility functions
- Internal error handling mechanisms
- Performance optimization internals
";
}
/// Deprecation policy
///
/// This structure documents the deprecation policy for the crate.
pub struct DeprecationPolicy;
impl DeprecationPolicy {
/// Deprecation timeline
///
/// APIs marked as deprecated will be removed according to this timeline:
/// - Major version (x.0.0): Deprecated APIs may be removed
/// - Minor version (0.x.0): Stable APIs will not be deprecated
/// - Patch version (0.0.x): No API changes except bug fixes
pub const TIMELINE: &'static str = "
Deprecation Timeline:
- Major version bumps (x.0.0): Deprecated APIs may be removed
- Minor version bumps (0.x.0): Stable APIs will not be deprecated,
experimental APIs may be deprecated
- Patch version bumps (0.0.x): No API changes except bug fixes
Deprecation Process:
1. API is marked as deprecated with #[deprecated] attribute
2. Alternative API is provided (if applicable)
3. Deprecation notice is included in release notes
4. API remains available for at least one major version
5. API is removed in subsequent major version
";
/// Migration guidelines
pub const MIGRATION: &'static str = "
Migration Guidelines:
When APIs are deprecated, migration paths will be provided:
- Clear documentation of replacement APIs
- Migration examples in release notes
- Automated migration tools when possible
- Community support during transition periods
";
}
/// Version compatibility matrix
///
/// This documents which versions are compatible with each other.
pub struct CompatibilityMatrix;
impl CompatibilityMatrix {
/// Check if two API versions are compatible
pub fn is_compatible(current: &str, required: &str) -> bool {
// Simple semantic version compatibility check
// In a real implementation, this would use a proper semver library
let current_parts: Vec<&str> = current.split('.').collect();
let required_parts: Vec<&str> = required.split('.').collect();
if current_parts.len() < 2 || required_parts.len() < 2 {
return false;
}
// Major version must match for compatibility
current_parts[0] == required_parts[0]
}
/// Get the compatibility level between two versions
pub fn compatibility_level(current: &str, required: &str) -> CompatibilityLevel {
if Self::is_compatible(current, required) {
CompatibilityLevel::Compatible
} else {
CompatibilityLevel::Incompatible
}
}
}
/// Compatibility levels between API versions
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CompatibilityLevel {
/// Fully compatible - no changes needed
Compatible,
/// Incompatible - breaking changes present
Incompatible,
}
/// Runtime API stability checking
///
/// This provides runtime checks for API stability and compatibility.
pub struct StabilityChecker;
impl StabilityChecker {
/// Check if the current crate version supports a required API version
pub fn supports_api_version(required_version: &str) -> bool {
CompatibilityMatrix::is_compatible(ApiVersion::CURRENT, required_version)
}
/// Get the stability level of a specific API component
pub fn get_stability_level(api_name: &str) -> StabilityLevel {
match api_name {
// Core stable APIs
"Dataset"
| "load_iris"
| "load_boston"
| "load_breast_cancer"
| "load_wine"
| "load_digits"
| "make_classification"
| "make_regression"
| "make_blobs"
| "make_circles"
| "make_moons"
| "k_fold_split"
| "stratified_k_fold_split"
| "train_test_split" => StabilityLevel::Stable,
// Experimental APIs
"GpuContext"
| "CloudClient"
| "DistributedProcessor"
| "MLPipeline"
| "StreamingIterator" => StabilityLevel::Experimental,
// Everything else is considered experimental for now
_ => StabilityLevel::Experimental,
}
}
/// Validate that experimental APIs are being used appropriately
pub fn validate_experimental_usage(api_name: &str) -> Result<(), String> {
match Self::get_stability_level(api_name) {
StabilityLevel::Experimental => {
eprintln!(
"Warning: '{api_name}' is an experimental API and may change in future versions"
);
Ok(())
}
StabilityLevel::Internal => Err(format!(
"Error: '{api_name}' is an internal API and should not be used directly"
)),
StabilityLevel::Stable => Ok(()),
}
}
}
/// Feature flags and their stability levels
pub mod feature_flags {
use super::StabilityLevel;
/// GPU acceleration features
pub const GPU: (&str, StabilityLevel) = ("gpu", StabilityLevel::Experimental);
/// Cloud storage features
pub const CLOUD: (&str, StabilityLevel) = ("cloud", StabilityLevel::Experimental);
/// Distributed processing features
pub const DISTRIBUTED: (&str, StabilityLevel) = ("distributed", StabilityLevel::Experimental);
/// Advanced ML integration features
pub const ML_ADVANCED: (&str, StabilityLevel) = ("ml_advanced", StabilityLevel::Experimental);
/// Streaming processing features
pub const STREAMING: (&str, StabilityLevel) = ("streaming", StabilityLevel::Experimental);
/// Domain-specific datasets
pub const DOMAIN_SPECIFIC: (&str, StabilityLevel) =
("domain_specific", StabilityLevel::Experimental);
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_compatibility_matrix() {
assert!(CompatibilityMatrix::is_compatible("0.1.0", "0.1.0"));
assert!(CompatibilityMatrix::is_compatible("0.1.1", "0.1.0"));
assert!(!CompatibilityMatrix::is_compatible("1.0.0", "0.1.0"));
assert!(!CompatibilityMatrix::is_compatible("0.1.0", "1.0.0"));
}
#[test]
fn test_stability_checker() {
assert_eq!(
StabilityChecker::get_stability_level("Dataset"),
StabilityLevel::Stable
);
assert_eq!(
StabilityChecker::get_stability_level("GpuContext"),
StabilityLevel::Experimental
);
}
#[test]
fn test_api_version() {
// Test that version strings are properly formatted (non-empty and contain dots)
assert!(ApiVersion::CURRENT.contains('.'));
assert!(ApiVersion::MIN_SUPPORTED.contains('.'));
assert!(ApiVersion::NEXT_PLANNED.contains('.'));
// Test that versions are properly ordered (basic check)
assert!(ApiVersion::CURRENT >= ApiVersion::MIN_SUPPORTED);
}
}