@@ -10,6 +10,8 @@ use crate::DataClass;
1010/// Although instances are encapsulated, it's possible to extract the instances when
1111/// classification is no longer needed.
1212///
13+ /// You rarely implement this trait by hand, instead use the [`classified`](data_privacy_macros::classified) macro.
14+ ///
1315/// # Example
1416///
1517/// ```rust
@@ -26,43 +28,45 @@ use crate::DataClass;
2628/// }
2729/// }
2830///
29- /// struct ClassifiedPerson {
30- /// person: Person
31- /// }
31+ /// struct ClassifiedPerson(Person);
3232///
3333/// impl ClassifiedPerson {
3434/// fn new(person: Person) -> Self {
35- /// Self { person }
35+ /// Self( person)
3636/// }
3737/// }
3838///
39- /// impl Classified<Person> for ClassifiedPerson {
39+ /// impl Classified for ClassifiedPerson {
40+ /// type Payload = Person;
41+ ///
4042/// fn declassify(self) -> Person {
41- /// self.person
43+ /// self.0
4244/// }
4345///
44- /// fn as_declassified(&self) -> &Person {
45- /// &self.person
46+ /// fn as_declassified(&self) -> &Person {
47+ /// &self.0
4648/// }
4749///
48- /// fn as_declassified_mut(&mut self) -> &mut Person {
49- /// &mut self.person
50+ /// fn as_declassified_mut(&mut self) -> &mut Person {
51+ /// &mut self.0
5052/// }
5153///
5254/// fn data_class(&self) -> DataClass {
5355/// DataClass::new("example_taxonomy", "classified_person")
5456/// }
5557/// }
5658/// ```
57- pub trait Classified < T > {
59+ pub trait Classified {
60+ type Payload ;
61+
5862 /// Exfiltrates the payload, allowing it to be used outside the classified context.
5963 ///
6064 /// Exfiltration should be done with caution, as it may expose sensitive information.
6165 ///
6266 /// # Returns
6367 /// The original payload.
6468 #[ must_use]
65- fn declassify ( self ) -> T ;
69+ fn declassify ( self ) -> Self :: Payload ;
6670
6771 /// Provides a reference to the declassified payload, allowing read access without ownership transfer.
6872 ///
@@ -71,7 +75,7 @@ pub trait Classified<T> {
7175 /// # Returns
7276 /// A reference to the original payload.
7377 #[ must_use]
74- fn as_declassified ( & self ) -> & T ;
78+ fn as_declassified ( & self ) -> & Self :: Payload ;
7579
7680 /// Provides a mutable reference to the declassified payload, allowing write access without ownership transfer.
7781 ///
@@ -80,15 +84,15 @@ pub trait Classified<T> {
8084 /// # Returns
8185 /// A mutable reference to the original payload.
8286 #[ must_use]
83- fn as_declassified_mut ( & mut self ) -> & mut T ;
87+ fn as_declassified_mut ( & mut self ) -> & mut Self :: Payload ;
8488
8589 /// Visits the payload with the provided operation.
86- fn visit ( & self , operation : impl FnOnce ( & T ) ) {
90+ fn visit ( & self , operation : impl FnOnce ( & Self :: Payload ) ) {
8791 operation ( self . as_declassified ( ) ) ;
8892 }
8993
9094 /// Visits the payload with the provided operation.
91- fn visit_mut ( & mut self , operation : impl FnOnce ( & mut T ) ) {
95+ fn visit_mut ( & mut self , operation : impl FnOnce ( & mut Self :: Payload ) ) {
9296 operation ( self . as_declassified_mut ( ) ) ;
9397 }
9498
@@ -106,7 +110,9 @@ mod tests {
106110 data : u32 ,
107111 }
108112
109- impl Classified < u32 > for ClassifiedExample {
113+ impl Classified for ClassifiedExample {
114+ type Payload = u32 ;
115+
110116 fn declassify ( self ) -> u32 {
111117 self . data
112118 }
0 commit comments