pub trait Event:
Clone
+ Debug
+ Send
+ Sync {
Show 33 methods
// Required methods
fn as_pdu(&self) -> &Pdu;
fn into_pdu(self) -> Pdu;
fn is_owned(&self) -> bool;
fn auth_events(
&self,
) -> impl DoubleEndedIterator<Item = &EventId> + Clone + Send + '_;
fn auth_events_into(
self,
) -> impl IntoIterator<IntoIter = impl Iterator<Item = OwnedEventId>> + Send;
fn content(&self) -> &RawJsonValue;
fn event_id(&self) -> &EventId;
fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch;
fn prev_events(
&self,
) -> impl DoubleEndedIterator<Item = &EventId> + Clone + Send + '_;
fn redacts(&self) -> Option<&EventId>;
fn rejected(&self) -> bool;
fn room_id(&self) -> &RoomId;
fn sender(&self) -> &UserId;
fn state_key(&self) -> Option<&str>;
fn kind(&self) -> &TimelineEventType;
fn unsigned(&self) -> Option<&RawJsonValue>;
// Provided methods
fn is_type_and_state_key(
&self,
kind: &TimelineEventType,
state_key: &str,
) -> bool { ... }
fn into_format<T>(self) -> T
where T: From<Owned<Self>>,
Self: Sized { ... }
fn to_format<'a, T>(&'a self) -> T
where T: From<Ref<'a, Self>>,
Self: Sized + 'a { ... }
fn contains_unsigned_property<T>(&self, property: &str, is_type: T) -> bool
where T: FnOnce(&JsonValue) -> bool,
Self: Sized { ... }
fn get_unsigned_property<T>(&self, property: &str) -> Result<T>
where T: for<'de> Deserialize<'de>,
Self: Sized { ... }
fn get_unsigned_as_value(&self) -> JsonValue
where Self: Sized { ... }
fn get_unsigned<T>(&self) -> Result<T>
where T: for<'de> Deserialize<'de>,
Self: Sized { ... }
fn get_content_as_value(&self) -> JsonValue
where Self: Sized { ... }
fn get_content<T>(&self) -> Result<T>
where for<'de> T: Deserialize<'de>,
Self: Sized { ... }
fn redacts_id(&self, room_rules: &RoomVersionRules) -> Option<OwnedEventId>
where Self: Sized { ... }
fn is_redacted(&self) -> bool
where Self: Sized { ... }
fn into_canonical_object(self) -> CanonicalJsonObject
where Self: Sized { ... }
fn to_canonical_object(&self) -> CanonicalJsonObject { ... }
fn into_value(self) -> JsonValue
where Self: Sized { ... }
fn to_value(&self) -> JsonValue { ... }
fn as_mut_pdu(&mut self) -> &mut Pdu { ... }
fn event_type(&self) -> &TimelineEventType { ... }
}Expand description
Abstraction of a PDU so users can have their own PDU types.
Required Methods§
Sourcefn as_pdu(&self) -> &Pdu
fn as_pdu(&self) -> &Pdu
Borrows the event as the common PDU representation.
Implementations may return their underlying PDU directly or a borrowed PDU representation with the same event data.
Sourcefn into_pdu(self) -> Pdu
fn into_pdu(self) -> Pdu
Converts the event into an owned common PDU representation.
Owned implementations can move their PDU. Borrowed implementations clone the PDU so the returned value owns every field.
Sourcefn is_owned(&self) -> bool
fn is_owned(&self) -> bool
Reports whether consuming conversion can move an owned PDU.
A false result indicates that into_pdu must clone borrowed event data.
The value can help callers choose a conversion path.
Sourcefn auth_events(
&self,
) -> impl DoubleEndedIterator<Item = &EventId> + Clone + Send + '_
fn auth_events( &self, ) -> impl DoubleEndedIterator<Item = &EventId> + Clone + Send + '_
All the authenticating events for this event.
Sourcefn auth_events_into(
self,
) -> impl IntoIterator<IntoIter = impl Iterator<Item = OwnedEventId>> + Send
fn auth_events_into( self, ) -> impl IntoIterator<IntoIter = impl Iterator<Item = OwnedEventId>> + Send
All the authenticating events for this event.
Sourcefn content(&self) -> &RawJsonValue
fn content(&self) -> &RawJsonValue
The event’s content.
Sourcefn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch
fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch
The time of creation on the originating server.
Sourcefn prev_events(
&self,
) -> impl DoubleEndedIterator<Item = &EventId> + Clone + Send + '_
fn prev_events( &self, ) -> impl DoubleEndedIterator<Item = &EventId> + Clone + Send + '_
The events before this event.
Sourcefn redacts(&self) -> Option<&EventId>
fn redacts(&self) -> Option<&EventId>
If this event is a redaction event this is the event it redacts.
Sourcefn unsigned(&self) -> Option<&RawJsonValue>
fn unsigned(&self) -> Option<&RawJsonValue>
Metadata container; peer-trusted only.
Provided Methods§
Sourcefn is_type_and_state_key(
&self,
kind: &TimelineEventType,
state_key: &str,
) -> bool
fn is_type_and_state_key( &self, kind: &TimelineEventType, state_key: &str, ) -> bool
Checks whether this event has both the requested type and state key.
Message-like events never match because their state key is absent. The comparison does not inspect event content.
Sourcefn into_format<T>(self) -> T
fn into_format<T>(self) -> T
Serialize into a Ruma JSON format, consuming.
Sourcefn contains_unsigned_property<T>(&self, property: &str, is_type: T) -> bool
fn contains_unsigned_property<T>(&self, property: &str, is_type: T) -> bool
Checks an unsigned-data property with a caller-supplied predicate.
The method returns false when the property is absent or the predicate rejects its value. Missing or malformed unsigned data is treated as empty.
Sourcefn get_unsigned_property<T>(&self, property: &str) -> Result<T>where
T: for<'de> Deserialize<'de>,
Self: Sized,
fn get_unsigned_property<T>(&self, property: &str) -> Result<T>where
T: for<'de> Deserialize<'de>,
Self: Sized,
Deserializes one property from the event’s unsigned data.
A missing property or malformed unsigned data is reported as not found. A value of the wrong type fails deserialization.
Sourcefn get_unsigned_as_value(&self) -> JsonValuewhere
Self: Sized,
fn get_unsigned_as_value(&self) -> JsonValuewhere
Self: Sized,
Deserializes the event’s unsigned data as a JSON value.
Missing or malformed unsigned data produces JSON null. Use
get_unsigned when the distinction must be preserved.
Sourcefn get_unsigned<T>(&self) -> Result<T>where
T: for<'de> Deserialize<'de>,
Self: Sized,
fn get_unsigned<T>(&self) -> Result<T>where
T: for<'de> Deserialize<'de>,
Self: Sized,
Deserializes the complete unsigned-data object into a requested type.
Missing unsigned data is reported as not found. Invalid JSON or a type mismatch fails deserialization.
Sourcefn get_content_as_value(&self) -> JsonValuewhere
Self: Sized,
fn get_content_as_value(&self) -> JsonValuewhere
Self: Sized,
Deserializes event content as an untyped JSON value.
The returned value owns its data and can be inspected without borrowing
the event. Typed consumers should prefer get_content.
§Panics
Panics when the stored content is not valid JSON.
Sourcefn get_content<T>(&self) -> Result<T>where
for<'de> T: Deserialize<'de>,
Self: Sized,
fn get_content<T>(&self) -> Result<T>where
for<'de> T: Deserialize<'de>,
Self: Sized,
Deserializes event content into a requested type.
The target type determines which event-content shape is accepted. Invalid JSON or a mismatched target type produces a bad-JSON result.
Sourcefn redacts_id(&self, room_rules: &RoomVersionRules) -> Option<OwnedEventId>where
Self: Sized,
fn redacts_id(&self, room_rules: &RoomVersionRules) -> Option<OwnedEventId>where
Self: Sized,
Resolves the event ID targeted by a redaction event.
The selected room rules determine whether the ID is read from event
content or the top-level redacts field. Non-redaction events and
malformed content return None.
Sourcefn is_redacted(&self) -> boolwhere
Self: Sized,
fn is_redacted(&self) -> boolwhere
Self: Sized,
Reports whether the event carries redaction metadata.
Redaction is recognized by the presence of unsigned.redacted_because.
Missing or malformed unsigned data is treated as not redacted.
Sourcefn into_canonical_object(self) -> CanonicalJsonObjectwhere
Self: Sized,
fn into_canonical_object(self) -> CanonicalJsonObjectwhere
Self: Sized,
Consumes the event and serializes its PDU as a canonical JSON object.
Implementations first convert the event to the common Pdu
representation. The resulting object preserves the stored event fields.
§Panics
Panics if the PDU cannot be serialized as a canonical JSON object.
Sourcefn to_canonical_object(&self) -> CanonicalJsonObject
fn to_canonical_object(&self) -> CanonicalJsonObject
Serializes the event’s PDU as an owned canonical JSON object.
The event remains available after conversion. The resulting object preserves the stored event fields.
§Panics
Panics if the PDU cannot be serialized as a canonical JSON object.
Sourcefn into_value(self) -> JsonValuewhere
Self: Sized,
fn into_value(self) -> JsonValuewhere
Self: Sized,
Consumes the event and serializes its PDU as a JSON value.
Implementations first convert the event to the common Pdu
representation. The returned value is an owned JSON object.
§Panics
Panics if the PDU cannot be serialized as JSON.
Sourcefn to_value(&self) -> JsonValue
fn to_value(&self) -> JsonValue
Serializes the event’s PDU as an owned JSON value.
The event remains available after conversion. The returned value is an owned JSON object.
§Panics
Panics if the PDU cannot be serialized as JSON.
Sourcefn as_mut_pdu(&mut self) -> &mut Pdu
fn as_mut_pdu(&mut self) -> &mut Pdu
Returns mutable access to the common PDU representation.
Implementations backed by a mutable Pdu override this method. The
default implementation marks mutable conversion as unsupported.
§Panics
Panics when the implementation does not provide mutable PDU access.
Sourcefn event_type(&self) -> &TimelineEventType
fn event_type(&self) -> &TimelineEventType
Returns the event’s timeline type.
This compatibility accessor delegates directly to kind. New callers
can use either name without changing the returned value.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".