use crate::checker::types::TypeId;
use std::collections::HashMap;
#[derive(Debug, Clone)]
pub struct DeprecationDetails {
pub message: String,
}
#[derive(Debug, Clone, Default)]
pub struct DeprecationTracker {
deprecated: HashMap<TypeId, DeprecationDetails>,
}
impl DeprecationTracker {
pub fn new() -> Self {
Self {
deprecated: HashMap::new(),
}
}
pub fn is_deprecated(&self, type_id: TypeId) -> bool {
self.deprecated.contains_key(&type_id)
}
pub fn get_deprecation_details(&self, type_id: TypeId) -> Option<&DeprecationDetails> {
self.deprecated.get(&type_id)
}
pub fn mark_deprecated(&mut self, type_id: TypeId, details: DeprecationDetails) {
self.deprecated.insert(type_id, details);
}
pub fn unmark_deprecated(&mut self, type_id: TypeId) {
self.deprecated.remove(&type_id);
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_deprecation_tracking() {
let mut tracker = DeprecationTracker::new();
assert!(!tracker.is_deprecated(10));
tracker.mark_deprecated(
10,
DeprecationDetails {
message: "Use NewType instead".to_string(),
},
);
assert!(tracker.is_deprecated(10));
assert_eq!(
tracker.get_deprecation_details(10).unwrap().message,
"Use NewType instead"
);
tracker.unmark_deprecated(10);
assert!(!tracker.is_deprecated(10));
}
}