From 63e32f2b0116f4707e01a9a09a490805c9a7fd53 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 27 Oct 2019 21:26:03 +0100 Subject: [PATCH] Exhausively match EventType in collection deserilization code --- src/collections/raw/all.rs | 53 +++++++++++++++++++++++++++-- src/collections/raw/only.rs | 67 +++++++++++++++++++++++++++++++++++-- 2 files changed, 116 insertions(+), 4 deletions(-) diff --git a/src/collections/raw/all.rs b/src/collections/raw/all.rs index 0f4ba82f..f45ee354 100644 --- a/src/collections/raw/all.rs +++ b/src/collections/raw/all.rs @@ -457,7 +457,27 @@ impl<'de> Deserialize<'de> for RoomEvent { from_value(value, RoomEvent::CustomRoom) } } - _ => Err(D::Error::custom("invalid event type")), + Direct + | Dummy + | ForwardedRoomKey + | FullyRead + | IgnoredUserList + | KeyVerificationAccept + | KeyVerificationCancel + | KeyVerificationKey + | KeyVerificationMac + | KeyVerificationRequest + | KeyVerificationStart + | Presence + | PushRules + | Receipt + | RoomKey + | RoomKeyRequest + | Tag + | Typing => Err(D::Error::custom("invalid event type")), + __Nonexhaustive => { + unreachable!("__Nonexhaustive variant should be impossible to obtain.") + } } } } @@ -491,7 +511,36 @@ impl<'de> Deserialize<'de> for StateEvent { RoomTombstone => from_value(value, StateEvent::RoomTombstone), RoomTopic => from_value(value, StateEvent::RoomTopic), Custom(_event_type_name) => from_value(value, StateEvent::CustomState), - _ => Err(D::Error::custom("invalid event type")), + CallAnswer + | CallCandidates + | CallHangup + | CallInvite + | Direct + | Dummy + | ForwardedRoomKey + | FullyRead + | IgnoredUserList + | KeyVerificationAccept + | KeyVerificationCancel + | KeyVerificationKey + | KeyVerificationMac + | KeyVerificationRequest + | KeyVerificationStart + | Presence + | PushRules + | Receipt + | RoomEncrypted + | RoomKey + | RoomKeyRequest + | RoomMessage + | RoomMessageFeedback + | RoomRedaction + | Sticker + | Tag + | Typing => Err(D::Error::custom("invalid event type")), + __Nonexhaustive => { + unreachable!("__Nonexhaustive variant should be impossible to obtain.") + } } } } diff --git a/src/collections/raw/only.rs b/src/collections/raw/only.rs index fd4fce70..2e4b8074 100644 --- a/src/collections/raw/only.rs +++ b/src/collections/raw/only.rs @@ -176,7 +176,34 @@ impl<'de> Deserialize<'de> for Event { Tag => from_value(value, Event::Tag), Typing => from_value(value, Event::Typing), Custom(_event_type_name) => from_value(value, Event::Custom), - _ => Err(D::Error::custom("invalid event type")), + CallAnswer + | CallCandidates + | CallHangup + | CallInvite + | RoomAliases + | RoomAvatar + | RoomCanonicalAlias + | RoomCreate + | RoomEncrypted + | RoomEncryption + | RoomGuestAccess + | RoomHistoryVisibility + | RoomJoinRules + | RoomMember + | RoomMessage + | RoomMessageFeedback + | RoomName + | RoomPinnedEvents + | RoomPowerLevels + | RoomServerAcl + | RoomThirdPartyInvite + | RoomTombstone + | RoomTopic + | RoomRedaction + | Sticker => Err(D::Error::custom("invalid event type")), + __Nonexhaustive => { + unreachable!("__Nonexhaustive variant should be impossible to obtain.") + } } } } @@ -203,7 +230,43 @@ impl<'de> Deserialize<'de> for RoomEvent { RoomRedaction => from_value(value, RoomEvent::RoomRedaction), Sticker => from_value(value, RoomEvent::Sticker), Custom(_event_type_name) => from_value(value, RoomEvent::CustomRoom), - _ => Err(D::Error::custom("invalid event type")), + Direct + | Dummy + | ForwardedRoomKey + | FullyRead + | IgnoredUserList + | KeyVerificationAccept + | KeyVerificationCancel + | KeyVerificationKey + | KeyVerificationMac + | KeyVerificationRequest + | KeyVerificationStart + | Presence + | PushRules + | Receipt + | RoomAvatar + | RoomAliases + | RoomCanonicalAlias + | RoomCreate + | RoomEncryption + | RoomGuestAccess + | RoomHistoryVisibility + | RoomJoinRules + | RoomKey + | RoomKeyRequest + | RoomMember + | RoomName + | RoomPinnedEvents + | RoomPowerLevels + | RoomServerAcl + | RoomThirdPartyInvite + | RoomTombstone + | RoomTopic + | Tag + | Typing => Err(D::Error::custom("invalid event type")), + __Nonexhaustive => { + unreachable!("__Nonexhaustive variant should be impossible to obtain.") + } } } }