Skip to main content

spectra_core/
classification.rs

1use serde::{Deserialize, Serialize};
2
3/// Per-field GDPR-oriented metadata for Spectra event schemas.
4#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5pub struct FieldClassification {
6    /// Whether the field contains personally identifiable information.
7    pub pii: bool,
8    /// Whether the field may be logged to developer consoles.
9    pub safe_for_console: bool,
10    /// Optional retention period in days for stored values.
11    #[serde(skip_serializing_if = "Option::is_none")]
12    pub retention_days: Option<u32>,
13    /// Optional human-readable purpose for collecting this field.
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub purpose: Option<String>,
16}
17
18#[cfg(test)]
19mod tests {
20    use super::*;
21
22    #[test]
23    fn classification_roundtrip() {
24        let c = FieldClassification {
25            pii: true,
26            safe_for_console: false,
27            retention_days: Some(30),
28            purpose: Some("debug".to_string()),
29        };
30        let json = serde_json::to_string(&c).expect("serialize");
31        let back: FieldClassification = serde_json::from_str(&json).expect("deserialize");
32        assert_eq!(back, c);
33    }
34}