Skip to main content

AlertTrigger

Enum AlertTrigger 

Source
#[non_exhaustive]
pub enum AlertTrigger { OffsetTrigger(OffsetTrigger), AbsoluteTrigger(AbsoluteTrigger), Unknown(Value), }
Expand description

Alert trigger — either offset-based, absolute, or an unknown future type (RFC 8984 §4.5.2).

The @type field on the wire selects the variant. The Unknown variant preserves any unrecognised trigger type for round-trip fidelity, as required by the spec: “Implementations MUST NOT trigger for trigger types they do not understand but MUST preserve them.”

Serde is implemented manually because #[serde(tag = "@type", other)] with a tuple variant is not supported by serde’s derive macros; other only works with unit variants in internally-tagged enums.

§Deserialization behaviour on malformed input

The custom Deserialize impl is deliberately permissive about the JSON shape of the input — only the @type tag drives the dispatch. Any input whose @type is missing, is not a string, or names a tag other than "OffsetTrigger" / "AbsoluteTrigger" is captured as AlertTrigger::Unknown carrying the original serde_json::Value unchanged. This includes:

  • top-level non-objects: null, arrays, numbers, strings, booleans
  • objects without an @type key
  • objects whose @type is a non-string value (null, 42, [])
  • objects whose @type is a string outside the known set

The rationale is round-trip fidelity per the spec’s preserve-mandate: rejecting at deserialize time would force consumers to drop data they are supposed to preserve. Consumers that need a stricter check should pattern-match on the variant and inspect the carried Value. A future well-typed AlertTrigger variant only ever displaces input that previously matched on @type exactly, so this permissive behaviour is forward-compatible with the spec’s evolution.

§Maintainer note: do NOT “clean up” this enum

The Unknown(serde_json::Value) variant exists because RFC 8984 §4.5.2 requires preservation of unrecognised trigger types. The following three “cleanups” all violate that MUST and break the regression tests alert_trigger_unknown_dispatch_on_hostile_input and alert_trigger_unknown_round_trips_through_serialize (both in this file), as well as alert_unknown_trigger_roundtrip in crate-jmap-calendars-types/tests/types_test.rs:

  1. Remove the Unknown variant. An exhaustive enum forces deserialize to either fail on an unknown @type (data loss + error) or silently drop the input (data loss). Both violate MUST preserve them.

  2. Replace Unknown(Value) with #[serde(other)] on a unit variant. A unit variant discards the carried JSON payload. The spec preserve- mandate requires the bytes round-trip, not just the variant discriminator. Unknown(String) and Unknown { at_type: String } have the same defect — they drop the inner fields.

  3. Add #[serde(deny_unknown_fields)] to AlertTrigger or to OffsetTrigger / AbsoluteTrigger. A peer that emits an extension field on a known trigger type (e.g. OffsetTrigger with a vendor field) would fail to deserialize entirely. The catch-all extra map on the inner structs is the workspace’s extras-preservation mechanism for that case; deny_unknown_fields fights it.

If you are reading this comment because you have a fourth “cleanup” in mind: confirm against the regression test and the spec passage (RFC 8984 §4.5.2) before proposing it. The design defense is bd:JMAP-1rwf.8.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

OffsetTrigger(OffsetTrigger)

Offset-based trigger: fires at offset relative to event start/end.

§

AbsoluteTrigger(AbsoluteTrigger)

Absolute trigger: fires at a specific UTC date-time.

§

Unknown(Value)

Any other trigger type; preserved opaquely as raw JSON.

Trait Implementations§

Source§

impl Clone for AlertTrigger

Source§

fn clone(&self) -> AlertTrigger

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AlertTrigger

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for AlertTrigger

Source§

fn deserialize<D>(d: D) -> Result<AlertTrigger, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for AlertTrigger

Source§

impl PartialEq for AlertTrigger

Source§

fn eq(&self, other: &AlertTrigger) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for AlertTrigger

Source§

fn serialize<S>( &self, s: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for AlertTrigger

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.