events: Make remaining types in room::* non-exhaustive
This commit is contained in:
		
							parent
							
								
									504c7ad06e
								
							
						
					
					
						commit
						55df2aa26a
					
				| @ -17,6 +17,7 @@ pub type PowerLevelsEvent = StateEvent<PowerLevelsEventContent>; | |||||||
| 
 | 
 | ||||||
| /// The payload for `PowerLevelsEvent`.
 | /// The payload for `PowerLevelsEvent`.
 | ||||||
| #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] | #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] | ||||||
|  | #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] | ||||||
| #[ruma_event(type = "m.room.power_levels", kind = State)] | #[ruma_event(type = "m.room.power_levels", kind = State)] | ||||||
| pub struct PowerLevelsEventContent { | pub struct PowerLevelsEventContent { | ||||||
|     /// The level required to ban a user.
 |     /// The level required to ban a user.
 | ||||||
| @ -116,8 +117,9 @@ pub struct PowerLevelsEventContent { | |||||||
|     pub notifications: NotificationPowerLevels, |     pub notifications: NotificationPowerLevels, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Default for PowerLevelsEventContent { | impl PowerLevelsEventContent { | ||||||
|     fn default() -> Self { |     /// Creates a `PowerLevelsEventContent` with all-default values.
 | ||||||
|  |     pub fn new() -> Self { | ||||||
|         // events_default and users_default having a default of 0 while the others have a default
 |         // events_default and users_default having a default of 0 while the others have a default
 | ||||||
|         // of 50 is not an oversight, these defaults are from the Matrix specification.
 |         // of 50 is not an oversight, these defaults are from the Matrix specification.
 | ||||||
|         Self { |         Self { | ||||||
| @ -135,6 +137,12 @@ impl Default for PowerLevelsEventContent { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | impl Default for PowerLevelsEventContent { | ||||||
|  |     fn default() -> Self { | ||||||
|  |         Self::new() | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| /// Used with `#[serde(skip_serializing_if)]` to omit default power levels.
 | /// Used with `#[serde(skip_serializing_if)]` to omit default power levels.
 | ||||||
| #[allow(clippy::trivially_copy_pass_by_ref)] | #[allow(clippy::trivially_copy_pass_by_ref)] | ||||||
| fn is_default_power_level(l: &Int) -> bool { | fn is_default_power_level(l: &Int) -> bool { | ||||||
|  | |||||||
| @ -55,7 +55,8 @@ pub struct SyncRedactionEvent { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /// A redaction of an event.
 | /// A redaction of an event.
 | ||||||
| #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] | #[derive(Clone, Debug, Default, Deserialize, Serialize, EventContent)] | ||||||
|  | #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] | ||||||
| #[ruma_event(type = "m.room.redaction", kind = Message)] | #[ruma_event(type = "m.room.redaction", kind = Message)] | ||||||
| pub struct RedactionEventContent { | pub struct RedactionEventContent { | ||||||
|     /// The reason for the redaction, if any.
 |     /// The reason for the redaction, if any.
 | ||||||
| @ -63,4 +64,16 @@ pub struct RedactionEventContent { | |||||||
|     pub reason: Option<String>, |     pub reason: Option<String>, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | impl RedactionEventContent { | ||||||
|  |     /// Creates an empty `RedactionEventContent`.
 | ||||||
|  |     pub fn new() -> Self { | ||||||
|  |         Self::default() | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /// Creates a `RedactionEventContent` with the given reason.
 | ||||||
|  |     pub fn with_reason(reason: String) -> Self { | ||||||
|  |         Self { reason: Some(reason) } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| impl RedactedStateEventContent for RedactedRedactionEventContent {} | impl RedactedStateEventContent for RedactedRedactionEventContent {} | ||||||
|  | |||||||
| @ -51,22 +51,40 @@ pub(crate) enum RelationJsonRepr { | |||||||
| 
 | 
 | ||||||
| /// Information about the event a "rich reply" is replying to.
 | /// Information about the event a "rich reply" is replying to.
 | ||||||
| #[derive(Clone, Debug, Deserialize, Serialize)] | #[derive(Clone, Debug, Deserialize, Serialize)] | ||||||
|  | #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] | ||||||
| pub struct InReplyTo { | pub struct InReplyTo { | ||||||
|     /// The event being replied to.
 |     /// The event being replied to.
 | ||||||
|     pub event_id: EventId, |     pub event_id: EventId, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | impl InReplyTo { | ||||||
|  |     /// Creates a new `InReplyTo` with the given event ID.
 | ||||||
|  |     pub fn new(event_id: EventId) -> Self { | ||||||
|  |         Self { event_id } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| /// A reference to another event.
 | /// A reference to another event.
 | ||||||
| #[derive(Clone, Debug, Deserialize, Serialize)] | #[derive(Clone, Debug, Deserialize, Serialize)] | ||||||
| #[cfg(feature = "unstable-pre-spec")] | #[cfg(feature = "unstable-pre-spec")] | ||||||
| #[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))] | #[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))] | ||||||
|  | #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] | ||||||
| pub struct Reference { | pub struct Reference { | ||||||
|     /// The event we are referencing.
 |     /// The event we are referencing.
 | ||||||
|     pub event_id: EventId, |     pub event_id: EventId, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | #[cfg(feature = "unstable-pre-spec")] | ||||||
|  | impl Reference { | ||||||
|  |     /// Creates a new `Reference` with the given event ID.
 | ||||||
|  |     pub fn new(event_id: EventId) -> Self { | ||||||
|  |         Self { event_id } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| /// An annotation for an event.
 | /// An annotation for an event.
 | ||||||
| #[derive(Clone, Debug, Deserialize, Serialize)] | #[derive(Clone, Debug, Deserialize, Serialize)] | ||||||
|  | #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] | ||||||
| pub struct Annotation { | pub struct Annotation { | ||||||
|     /// The event that is being annotated.
 |     /// The event that is being annotated.
 | ||||||
|     pub event_id: EventId, |     pub event_id: EventId, | ||||||
| @ -75,15 +93,31 @@ pub struct Annotation { | |||||||
|     pub key: String, |     pub key: String, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | impl Annotation { | ||||||
|  |     /// Creates a new `Annotation` with the given event ID and key.
 | ||||||
|  |     pub fn new(event_id: EventId, key: String) -> Self { | ||||||
|  |         Self { event_id, key } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| /// An event replacing another event.
 | /// An event replacing another event.
 | ||||||
| #[derive(Clone, Debug, Deserialize, Serialize)] | #[derive(Clone, Debug, Deserialize, Serialize)] | ||||||
| #[cfg(feature = "unstable-pre-spec")] | #[cfg(feature = "unstable-pre-spec")] | ||||||
| #[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))] | #[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))] | ||||||
|  | #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] | ||||||
| pub struct Replacement { | pub struct Replacement { | ||||||
|     /// The event this event is replacing.
 |     /// The event this event is replacing.
 | ||||||
|     pub event_id: EventId, |     pub event_id: EventId, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | #[cfg(feature = "unstable-pre-spec")] | ||||||
|  | impl Replacement { | ||||||
|  |     /// Creates a new `Replacement` with the given event ID.
 | ||||||
|  |     pub fn new(event_id: EventId) -> Self { | ||||||
|  |         Self { event_id } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| #[cfg(test)] | #[cfg(test)] | ||||||
| mod tests { | mod tests { | ||||||
|     use matches::assert_matches; |     use matches::assert_matches; | ||||||
|  | |||||||
| @ -10,6 +10,7 @@ pub type ServerAclEvent = StateEvent<ServerAclEventContent>; | |||||||
| 
 | 
 | ||||||
| /// The payload for `ServerAclEvent`.
 | /// The payload for `ServerAclEvent`.
 | ||||||
| #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] | #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] | ||||||
|  | #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] | ||||||
| #[ruma_event(type = "m.room.server_acl", kind = State)] | #[ruma_event(type = "m.room.server_acl", kind = State)] | ||||||
| pub struct ServerAclEventContent { | pub struct ServerAclEventContent { | ||||||
|     /// True to allow server names that are IP address literals. False to deny.
 |     /// True to allow server names that are IP address literals. False to deny.
 | ||||||
| @ -38,6 +39,14 @@ pub struct ServerAclEventContent { | |||||||
|     pub deny: Vec<String>, |     pub deny: Vec<String>, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | impl ServerAclEventContent { | ||||||
|  |     /// Creates a new `ServerAclEventContent` with the given IP literal allowance flag, allowed and
 | ||||||
|  |     /// denied servers.
 | ||||||
|  |     pub fn new(allow_ip_literals: bool, allow: Vec<String>, deny: Vec<String>) -> Self { | ||||||
|  |         Self { allow_ip_literals, allow, deny } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| #[cfg(test)] | #[cfg(test)] | ||||||
| mod tests { | mod tests { | ||||||
|     use ruma_serde::Raw; |     use ruma_serde::Raw; | ||||||
|  | |||||||
| @ -14,6 +14,7 @@ pub type ThirdPartyInviteEvent = StateEvent<ThirdPartyInviteEventContent>; | |||||||
| 
 | 
 | ||||||
| /// The payload for `ThirdPartyInviteEvent`.
 | /// The payload for `ThirdPartyInviteEvent`.
 | ||||||
| #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] | #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] | ||||||
|  | #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] | ||||||
| #[ruma_event(type = "m.room.third_party_invite", kind = State)] | #[ruma_event(type = "m.room.third_party_invite", kind = State)] | ||||||
| pub struct ThirdPartyInviteEventContent { | pub struct ThirdPartyInviteEventContent { | ||||||
|     /// A user-readable string which represents the user who has been invited.
 |     /// A user-readable string which represents the user who has been invited.
 | ||||||
| @ -42,8 +43,17 @@ pub struct ThirdPartyInviteEventContent { | |||||||
|     pub public_keys: Option<Vec<PublicKey>>, |     pub public_keys: Option<Vec<PublicKey>>, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | impl ThirdPartyInviteEventContent { | ||||||
|  |     /// Creates a new `ThirdPartyInviteEventContent` with the given display name, key validity url
 | ||||||
|  |     /// and public key.
 | ||||||
|  |     pub fn new(display_name: String, key_validity_url: String, public_key: String) -> Self { | ||||||
|  |         Self { display_name, key_validity_url, public_key, public_keys } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| /// A public key for signing a third party invite token.
 | /// A public key for signing a third party invite token.
 | ||||||
| #[derive(Clone, Debug, Deserialize, Serialize)] | #[derive(Clone, Debug, Deserialize, Serialize)] | ||||||
|  | #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] | ||||||
| pub struct PublicKey { | pub struct PublicKey { | ||||||
|     /// An optional URL which can be fetched to validate whether the key has been revoked.
 |     /// An optional URL which can be fetched to validate whether the key has been revoked.
 | ||||||
|     ///
 |     ///
 | ||||||
| @ -55,3 +65,10 @@ pub struct PublicKey { | |||||||
|     /// A Base64-encoded Ed25519 key with which the token must be signed.
 |     /// A Base64-encoded Ed25519 key with which the token must be signed.
 | ||||||
|     pub public_key: String, |     pub public_key: String, | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | impl PublicKey { | ||||||
|  |     /// Creates a new `PublicKey` with the given base64-encoded ed25519 key.
 | ||||||
|  |     pub fn new(public_key: String) -> Self { | ||||||
|  |         Self { key_validity_url: None, public_key } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | |||||||
| @ -13,6 +13,7 @@ pub type TombstoneEvent = StateEvent<TombstoneEventContent>; | |||||||
| /// The payload for `TombstoneEvent`.
 | /// The payload for `TombstoneEvent`.
 | ||||||
| #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] | #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] | ||||||
| #[ruma_event(type = "m.room.tombstone", kind = State)] | #[ruma_event(type = "m.room.tombstone", kind = State)] | ||||||
|  | #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] | ||||||
| pub struct TombstoneEventContent { | pub struct TombstoneEventContent { | ||||||
|     /// A server-defined message.
 |     /// A server-defined message.
 | ||||||
|     ///
 |     ///
 | ||||||
| @ -24,3 +25,10 @@ pub struct TombstoneEventContent { | |||||||
|     /// The new room the client should be visiting.
 |     /// The new room the client should be visiting.
 | ||||||
|     pub replacement_room: RoomId, |     pub replacement_room: RoomId, | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | impl TombstoneEventContent { | ||||||
|  |     /// Creates a new `TombstoneEventContent` with the given body and replacement room ID.
 | ||||||
|  |     pub fn new(body: String, replacement_room: RoomId) -> Self { | ||||||
|  |         Self { body, replacement_room } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | |||||||
| @ -10,8 +10,16 @@ pub type TopicEvent = StateEvent<TopicEventContent>; | |||||||
| 
 | 
 | ||||||
| /// The payload for `TopicEvent`.
 | /// The payload for `TopicEvent`.
 | ||||||
| #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] | #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] | ||||||
|  | #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] | ||||||
| #[ruma_event(type = "m.room.topic", kind = State)] | #[ruma_event(type = "m.room.topic", kind = State)] | ||||||
| pub struct TopicEventContent { | pub struct TopicEventContent { | ||||||
|     /// The topic text.
 |     /// The topic text.
 | ||||||
|     pub topic: String, |     pub topic: String, | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | impl TopicEventContent { | ||||||
|  |     /// Creates a new `TopicEventContent` with the given topic.
 | ||||||
|  |     pub fn new(topic: String) -> Self { | ||||||
|  |         Self { topic } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user