scirs2_datasets/
stability.rs

1//! API Stability Guarantees for scirs2-datasets
2//!
3//! This module defines the API stability levels and compatibility guarantees
4//! for the scirs2-datasets crate. It provides documentation and markers for
5//! different stability levels of the public API.
6
7/// API stability levels for different components of the crate
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum StabilityLevel {
10    /// Stable API - Guaranteed backward compatibility within major versions
11    ///
12    /// These APIs will not change in breaking ways within the same major version.
13    /// New functionality may be added with minor version bumps, but existing
14    /// functionality will remain backward compatible.
15    Stable,
16
17    /// Experimental API - Subject to change in minor versions
18    ///
19    /// These APIs are considered experimental and may change or be removed
20    /// in future minor versions. Use with caution in production code.
21    Experimental,
22
23    /// Internal API - Not part of the public API
24    ///
25    /// These APIs are for internal use only and may change without notice.
26    /// They should not be used by external code.
27    Internal,
28}
29
30/// Trait to mark API stability level for types and functions
31pub trait ApiStability {
32    /// The stability level of this API component
33    const STABILITY: StabilityLevel;
34
35    /// Optional version when this API was introduced
36    const INTRODUCED_IN: Option<&'static str> = None;
37
38    /// Optional version when this API was stabilized (if applicable)
39    const STABILIZED_IN: Option<&'static str> = None;
40
41    /// Optional deprecation information
42    const DEPRECATED_IN: Option<&'static str> = None;
43}
44
45/// Macro to easily annotate APIs with stability information
46#[macro_export]
47macro_rules! api_stability {
48    (stable, $item:item) => {
49        #[doc = " **API Stability: Stable** - Guaranteed backward compatibility within major versions"]
50        $item
51    };
52    (experimental, $item:item) => {
53        #[doc = " **API Stability: Experimental** - Subject to change in minor versions"]
54        $item
55    };
56    (internal, $item:item) => {
57        #[doc = " **API Stability: Internal** - Not part of the public API"]
58        $item
59    };
60}
61
62/// Current API version and compatibility matrix
63pub struct ApiVersion;
64
65impl ApiVersion {
66    /// Current API version
67    pub const CURRENT: &'static str = "0.1.0-beta.4";
68
69    /// Minimum supported API version for backward compatibility
70    pub const MIN_SUPPORTED: &'static str = "0.1.0";
71
72    /// Next planned API version
73    pub const NEXT_PLANNED: &'static str = "0.2.0";
74}
75
76/// API compatibility guarantees
77///
78/// This structure documents the compatibility guarantees for different
79/// components of the scirs2-datasets crate.
80pub struct CompatibilityGuarantees;
81
82impl CompatibilityGuarantees {
83    /// Core dataset types and basic operations
84    ///
85    /// These are considered stable and will maintain backward compatibility:
86    /// - `Dataset` struct and its public methods
87    /// - Basic dataset loading functions (`load_iris`, `load_boston`, etc.)
88    /// - Core data generation functions (`make_classification`, `make_regression`, etc.)
89    /// - Cross-validation utilities
90    /// - Basic dataset manipulation functions
91    pub const CORE_API_STABLE: &'static str = "
92    The following APIs are considered stable and will maintain backward compatibility:
93    
94    - Dataset struct and its public methods (n_samples, n_features, etc.)
95    - Toy dataset loaders (load_iris, load_boston, load_breast_cancer, etc.)
96    - Core data generators (make_classification, make_regression, make_blobs, etc.)
97    - Cross-validation utilities (k_fold_split, stratified_k_fold_split, etc.)
98    - Basic dataset utilities (train_test_split, normalize_features, etc.)
99    - Error types and Result definitions
100    ";
101
102    /// Advanced features that are experimental
103    ///
104    /// These features may change in minor versions:
105    /// - GPU acceleration APIs
106    /// - Cloud storage integration
107    /// - Distributed processing
108    /// - Advanced ML pipeline integration
109    /// - Domain-specific datasets
110    pub const EXPERIMENTAL_API: &'static str = "
111    The following APIs are experimental and may change in minor versions:
112    
113    - GPU acceleration (gpu module)
114    - Cloud storage integration (cloud module)
115    - Distributed processing (distributed module)
116    - Advanced ML pipeline features (ml_integration advanced features)
117    - Domain-specific datasets (domain_specific module)
118    - Streaming dataset processing (streaming module)
119    - Advanced data generators (advanced_generators module)
120    ";
121
122    /// Internal APIs that may change without notice
123    ///
124    /// These are not part of the public API:
125    /// - Cache implementation details
126    /// - Internal data structures
127    /// - Private utility functions
128    pub const INTERNAL_API: &'static str = "
129    The following APIs are internal and may change without notice:
130    
131    - Cache implementation details
132    - Internal registry structures
133    - Private utility functions
134    - Internal error handling mechanisms
135    - Performance optimization internals
136    ";
137}
138
139/// Deprecation policy
140///
141/// This structure documents the deprecation policy for the crate.
142pub struct DeprecationPolicy;
143
144impl DeprecationPolicy {
145    /// Deprecation timeline
146    ///
147    /// APIs marked as deprecated will be removed according to this timeline:
148    /// - Major version (x.0.0): Deprecated APIs may be removed
149    /// - Minor version (0.x.0): Stable APIs will not be deprecated
150    /// - Patch version (0.0.x): No API changes except bug fixes
151    pub const TIMELINE: &'static str = "
152    Deprecation Timeline:
153    
154    - Major version bumps (x.0.0): Deprecated APIs may be removed
155    - Minor version bumps (0.x.0): Stable APIs will not be deprecated, 
156      experimental APIs may be deprecated
157    - Patch version bumps (0.0.x): No API changes except bug fixes
158    
159    Deprecation Process:
160    1. API is marked as deprecated with #[deprecated] attribute
161    2. Alternative API is provided (if applicable)
162    3. Deprecation notice is included in release notes
163    4. API remains available for at least one major version
164    5. API is removed in subsequent major version
165    ";
166
167    /// Migration guidelines
168    pub const MIGRATION: &'static str = "
169    Migration Guidelines:
170    
171    When APIs are deprecated, migration paths will be provided:
172    - Clear documentation of replacement APIs
173    - Migration examples in release notes
174    - Automated migration tools when possible
175    - Community support during transition periods
176    ";
177}
178
179/// Version compatibility matrix
180///
181/// This documents which versions are compatible with each other.
182pub struct CompatibilityMatrix;
183
184impl CompatibilityMatrix {
185    /// Check if two API versions are compatible
186    pub fn is_compatible(current: &str, required: &str) -> bool {
187        // Simple semantic version compatibility check
188        // In a real implementation, this would use a proper semver library
189        let current_parts: Vec<&str> = current.split('.').collect();
190        let required_parts: Vec<&str> = required.split('.').collect();
191
192        if current_parts.len() < 2 || required_parts.len() < 2 {
193            return false;
194        }
195
196        // Major version must match for compatibility
197        current_parts[0] == required_parts[0]
198    }
199
200    /// Get the compatibility level between two versions
201    pub fn compatibility_level(current: &str, required: &str) -> CompatibilityLevel {
202        if Self::is_compatible(current, required) {
203            CompatibilityLevel::Compatible
204        } else {
205            CompatibilityLevel::Incompatible
206        }
207    }
208}
209
210/// Compatibility levels between API versions
211#[derive(Debug, Clone, Copy, PartialEq, Eq)]
212pub enum CompatibilityLevel {
213    /// Fully compatible - no changes needed
214    Compatible,
215    /// Incompatible - breaking changes present
216    Incompatible,
217}
218
219/// Runtime API stability checking
220///
221/// This provides runtime checks for API stability and compatibility.
222pub struct StabilityChecker;
223
224impl StabilityChecker {
225    /// Check if the current crate version supports a required API version
226    pub fn supports_api_version(required_version: &str) -> bool {
227        CompatibilityMatrix::is_compatible(ApiVersion::CURRENT, required_version)
228    }
229
230    /// Get the stability level of a specific API component
231    pub fn get_stability_level(api_name: &str) -> StabilityLevel {
232        match api_name {
233            // Core stable APIs
234            "Dataset"
235            | "load_iris"
236            | "load_boston"
237            | "load_breast_cancer"
238            | "load_wine"
239            | "load_digits"
240            | "make_classification"
241            | "make_regression"
242            | "make_blobs"
243            | "make_circles"
244            | "make_moons"
245            | "k_fold_split"
246            | "stratified_k_fold_split"
247            | "train_test_split" => StabilityLevel::Stable,
248
249            // Experimental APIs
250            "GpuContext"
251            | "CloudClient"
252            | "DistributedProcessor"
253            | "MLPipeline"
254            | "StreamingIterator" => StabilityLevel::Experimental,
255
256            // Everything else is considered experimental for now
257            _ => StabilityLevel::Experimental,
258        }
259    }
260
261    /// Validate that experimental APIs are being used appropriately
262    pub fn validate_experimental_usage(api_name: &str) -> Result<(), String> {
263        match Self::get_stability_level(api_name) {
264            StabilityLevel::Experimental => {
265                eprintln!(
266                    "Warning: '{api_name}' is an experimental API and may change in future versions"
267                );
268                Ok(())
269            }
270            StabilityLevel::Internal => Err(format!(
271                "Error: '{api_name}' is an internal API and should not be used directly"
272            )),
273            StabilityLevel::Stable => Ok(()),
274        }
275    }
276}
277
278/// Feature flags and their stability levels
279pub mod feature_flags {
280    use super::StabilityLevel;
281
282    /// GPU acceleration features
283    pub const GPU: (&str, StabilityLevel) = ("gpu", StabilityLevel::Experimental);
284
285    /// Cloud storage features  
286    pub const CLOUD: (&str, StabilityLevel) = ("cloud", StabilityLevel::Experimental);
287
288    /// Distributed processing features
289    pub const DISTRIBUTED: (&str, StabilityLevel) = ("distributed", StabilityLevel::Experimental);
290
291    /// Advanced ML integration features
292    pub const ML_ADVANCED: (&str, StabilityLevel) = ("ml_advanced", StabilityLevel::Experimental);
293
294    /// Streaming processing features
295    pub const STREAMING: (&str, StabilityLevel) = ("streaming", StabilityLevel::Experimental);
296
297    /// Domain-specific datasets
298    pub const DOMAIN_SPECIFIC: (&str, StabilityLevel) =
299        ("domain_specific", StabilityLevel::Experimental);
300}
301
302#[cfg(test)]
303mod tests {
304    use super::*;
305
306    #[test]
307    fn test_compatibility_matrix() {
308        assert!(CompatibilityMatrix::is_compatible("0.1.0", "0.1.0"));
309        assert!(CompatibilityMatrix::is_compatible("0.1.1", "0.1.0"));
310        assert!(!CompatibilityMatrix::is_compatible("1.0.0", "0.1.0"));
311        assert!(!CompatibilityMatrix::is_compatible("0.1.0", "1.0.0"));
312    }
313
314    #[test]
315    fn test_stability_checker() {
316        assert_eq!(
317            StabilityChecker::get_stability_level("Dataset"),
318            StabilityLevel::Stable
319        );
320        assert_eq!(
321            StabilityChecker::get_stability_level("GpuContext"),
322            StabilityLevel::Experimental
323        );
324    }
325
326    #[test]
327    fn test_api_version() {
328        // Test that version strings are properly formatted (non-empty and contain dots)
329        assert!(ApiVersion::CURRENT.contains('.'));
330        assert!(ApiVersion::MIN_SUPPORTED.contains('.'));
331        assert!(ApiVersion::NEXT_PLANNED.contains('.'));
332
333        // Test that versions are properly ordered (basic check)
334        assert!(ApiVersion::CURRENT >= ApiVersion::MIN_SUPPORTED);
335    }
336}