Skip to main content

Event

Trait Event 

Source
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§

Source

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.

Source

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.

Source

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.

Source

fn auth_events( &self, ) -> impl DoubleEndedIterator<Item = &EventId> + Clone + Send + '_

All the authenticating events for this event.

Source

fn auth_events_into( self, ) -> impl IntoIterator<IntoIter = impl Iterator<Item = OwnedEventId>> + Send

All the authenticating events for this event.

Source

fn content(&self) -> &RawJsonValue

The event’s content.

Source

fn event_id(&self) -> &EventId

The EventId of this event.

Source

fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch

The time of creation on the originating server.

Source

fn prev_events( &self, ) -> impl DoubleEndedIterator<Item = &EventId> + Clone + Send + '_

The events before this event.

Source

fn redacts(&self) -> Option<&EventId>

If this event is a redaction event this is the event it redacts.

Source

fn rejected(&self) -> bool

Source

fn room_id(&self) -> &RoomId

The RoomId of this event.

Source

fn sender(&self) -> &UserId

The UserId of this event.

Source

fn state_key(&self) -> Option<&str>

The state key for this event.

Source

fn kind(&self) -> &TimelineEventType

The event type.

Source

fn unsigned(&self) -> Option<&RawJsonValue>

Metadata container; peer-trusted only.

Provided Methods§

Source

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.

Source

fn into_format<T>(self) -> T
where T: From<Owned<Self>>, Self: Sized,

Serialize into a Ruma JSON format, consuming.

Source

fn to_format<'a, T>(&'a self) -> T
where T: From<Ref<'a, Self>>, Self: Sized + 'a,

Serialize into a Ruma JSON format

Source

fn contains_unsigned_property<T>(&self, property: &str, is_type: T) -> bool
where T: FnOnce(&JsonValue) -> bool, Self: Sized,

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.

Source

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.

Source

fn get_unsigned_as_value(&self) -> JsonValue
where 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.

Source

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.

Source

fn get_content_as_value(&self) -> JsonValue
where 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.

Source

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.

Source

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.

Source

fn is_redacted(&self) -> bool
where 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.

Source

fn into_canonical_object(self) -> CanonicalJsonObject
where 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.

Source

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.

Source

fn into_value(self) -> JsonValue
where 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.

Source

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.

Source

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.

Source

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".

Implementors§

Source§

impl Event for &Pdu
where Self: Send,

Source§

impl Event for Pdu
where Self: Send + Sync + 'static,