Skip to main content

tuwunel_matrix/event/
type_ext.rs

1use ruma::events::{StateEventType, TimelineEventType};
2
3use super::StateKey;
4
5/// Convenience trait for adding event type plus state key to state maps.
6pub trait TypeExt {
7	/// Pairs this event type with an owned state key.
8	///
9	/// Timeline event types are converted to their state-event type spelling.
10	/// Borrowed event types are cloned as needed for the returned pair.
11	fn with_state_key(self, state_key: impl Into<StateKey>) -> (StateEventType, StateKey);
12}
13
14impl TypeExt for StateEventType {
15	fn with_state_key(self, state_key: impl Into<StateKey>) -> (StateEventType, StateKey) {
16		(self, state_key.into())
17	}
18}
19
20impl TypeExt for &StateEventType {
21	fn with_state_key(self, state_key: impl Into<StateKey>) -> (StateEventType, StateKey) {
22		(self.clone(), state_key.into())
23	}
24}
25
26impl TypeExt for TimelineEventType {
27	fn with_state_key(self, state_key: impl Into<StateKey>) -> (StateEventType, StateKey) {
28		(self.to_cow_str().into(), state_key.into())
29	}
30}
31
32impl TypeExt for &TimelineEventType {
33	fn with_state_key(self, state_key: impl Into<StateKey>) -> (StateEventType, StateKey) {
34		(self.to_cow_str().into(), state_key.into())
35	}
36}