pub struct Forgettable<T>(/* private fields */);Expand description
Wrapper for event fields containing data that can be forgotten (e.g., for GDPR).
This is an opaque struct — internal state is private so callers cannot
pattern-match to extract the raw value. Use Forgettable::value() to get
a ForgettableRef that derefs to T but does not implement Serialize,
preventing accidental re-serialization of personal data.
§Serde Behavior
- Both set and forgotten values serialize as
nullto prevent data leakage when events are serialized to secondary stores. - Deserializing
nullproduces a forgotten value, non-null produces a set value. - Real values are extracted via [
__extract_payload_value] before serde runs, and stored in the forgettable payloads table.
§JSON Schema
With the json-schema feature enabled, Forgettable<T> implements
schemars::JsonSchema by delegating to Option<T>, matching the
value-or-null serialized shape — no field-level #[schemars(with = ...)]
is needed on containing types.
§Repository Guard
An event type with Forgettable<T> fields must be backed by a repository
that enables forgettable in #[es_repo(...)]; otherwise the payloads are
never scrubbed. The repository derive cannot see the event’s
forgettable-ness at macro time, so for a repository that omits the flag it
emits a const assertion on the event’s inherent HAS_FORGETTABLE_FIELDS.
This is that assertion verbatim, and it fails to compile because the event
is forgettable:
use es_entity::*;
use serde::{Deserialize, Serialize};
es_entity::entity_id! { UserId }
#[derive(EsEvent, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
#[es_event(id = "UserId")]
pub enum UserEvent {
Initialized { id: UserId, name: Forgettable<String> },
}
const _: () = assert!(
!UserEvent::HAS_FORGETTABLE_FIELDS,
"event type has Forgettable fields but this repo does not enable `forgettable`; add `forgettable` to #[es_repo(...)]"
);§Example
use es_entity::Forgettable;
let name: Forgettable<String> = Forgettable::new("Alice".to_string());
assert_eq!(&*name.value().unwrap(), "Alice");
let forgotten: Forgettable<String> = Forgettable::forgotten();
assert!(forgotten.value().is_none());Implementations§
Source§impl<T> Forgettable<T>
impl<T> Forgettable<T>
Sourcepub fn value(&self) -> Option<ForgettableRef<'_, T>>
pub fn value(&self) -> Option<ForgettableRef<'_, T>>
Returns a ForgettableRef wrapping the inner value, or None if forgotten.
ForgettableRef implements Deref<Target = T> but not Serialize,
so you can read the value but cannot accidentally serialize it.
Sourcepub fn is_forgotten(&self) -> bool
pub fn is_forgotten(&self) -> bool
Returns true if the value has been forgotten.
Trait Implementations§
Source§impl<T: Clone> Clone for Forgettable<T>
impl<T: Clone> Clone for Forgettable<T>
Source§fn clone(&self) -> Forgettable<T>
fn clone(&self) -> Forgettable<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: Debug> Debug for Forgettable<T>
impl<T: Debug> Debug for Forgettable<T>
Source§impl<T> Default for Forgettable<T>
impl<T> Default for Forgettable<T>
Source§impl<'de, T: Deserialize<'de>> Deserialize<'de> for Forgettable<T>
impl<'de, T: Deserialize<'de>> Deserialize<'de> for Forgettable<T>
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
impl<T: Eq> Eq for Forgettable<T>
Source§impl<T> From<T> for Forgettable<T>
impl<T> From<T> for Forgettable<T>
Source§impl<T: Hash> Hash for Forgettable<T>
impl<T: Hash> Hash for Forgettable<T>
Source§impl<T: PartialEq> PartialEq for Forgettable<T>
impl<T: PartialEq> PartialEq for Forgettable<T>
Source§impl<T: Serialize> Serialize for Forgettable<T>
impl<T: Serialize> Serialize for Forgettable<T>
impl<T: PartialEq> StructuralPartialEq for Forgettable<T>
Auto Trait Implementations§
impl<T> Freeze for Forgettable<T>where
T: Freeze,
impl<T> RefUnwindSafe for Forgettable<T>where
T: RefUnwindSafe,
impl<T> Send for Forgettable<T>where
T: Send,
impl<T> Sync for Forgettable<T>where
T: Sync,
impl<T> Unpin for Forgettable<T>where
T: Unpin,
impl<T> UnsafeUnpin for Forgettable<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Forgettable<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more