events: Make all pub structs non_exhaustive

This commit is contained in:
Devin Ragotzy 2021-06-18 08:21:01 -04:00 committed by Jonas Platte
parent 4312085b4a
commit e05aad184e
31 changed files with 137 additions and 30 deletions

View File

@ -204,6 +204,20 @@ pub fn expand_event_content(
quote! { true } quote! { true }
}; };
let initializer = if kept_redacted_fields.is_empty() {
let doc = format!("Creates an empty {}.", redacted_ident);
quote! {
impl #redacted_ident {
#[doc = #doc]
pub fn new() -> Self {
Self
}
}
}
} else {
TokenStream::new()
};
let redacted_event_content = let redacted_event_content =
generate_event_content_impl(&redacted_ident, event_type, ruma_events); generate_event_content_impl(&redacted_ident, event_type, ruma_events);
@ -237,8 +251,11 @@ pub fn expand_event_content(
#[doc = #doc] #[doc = #doc]
#[derive(Clone, Debug, #serde::Deserialize, #serde::Serialize)] #[derive(Clone, Debug, #serde::Deserialize, #serde::Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct #redacted_ident #redacted_fields pub struct #redacted_ident #redacted_fields
#initializer
#redacted_event_content #redacted_event_content
#[automatically_derived] #[automatically_derived]

View File

@ -638,9 +638,7 @@ fn generate_redacted_fields(
if name == "unsigned" { if name == "unsigned" {
quote! { quote! {
unsigned: #ruma_events::RedactedUnsigned { unsigned: #ruma_events::RedactedUnsigned::new_because(::std::boxed::Box::new(redaction)),
redacted_because: Some(::std::boxed::Box::new(redaction)),
},
} }
} else { } else {
quote! { quote! {

View File

@ -15,6 +15,7 @@ use crate::{
/// A custom event's type and `content` JSON object. /// A custom event's type and `content` JSON object.
#[derive(Clone, Debug, Serialize)] #[derive(Clone, Debug, Serialize)]
#[allow(clippy::exhaustive_structs)]
pub struct CustomEventContent { pub struct CustomEventContent {
/// The event type string. /// The event type string.
#[serde(skip)] #[serde(skip)]
@ -60,6 +61,7 @@ impl StateEventContent for CustomEventContent {}
/// A custom event that has been redacted. /// A custom event that has been redacted.
#[derive(Clone, Debug, Serialize)] #[derive(Clone, Debug, Serialize)]
#[allow(clippy::exhaustive_structs)]
pub struct RedactedCustomEventContent { pub struct RedactedCustomEventContent {
// This field is marked skipped but will be present because deserialization // This field is marked skipped but will be present because deserialization
// passes the `type` field of the JSON event to the events `EventContent::from_parts` method. // passes the `type` field of the JSON event to the events `EventContent::from_parts` method.

View File

@ -17,6 +17,7 @@ pub type DirectEvent = crate::GlobalAccountDataEvent<DirectEventContent>;
/// A mapping of `UserId`s to a list of `RoomId`s which are considered *direct* for that /// A mapping of `UserId`s to a list of `RoomId`s which are considered *direct* for that
/// particular user. /// particular user.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[allow(clippy::exhaustive_structs)]
#[ruma_event(type = "m.direct", kind = GlobalAccountData)] #[ruma_event(type = "m.direct", kind = GlobalAccountData)]
pub struct DirectEventContent(pub BTreeMap<UserId, Vec<RoomId>>); pub struct DirectEventContent(pub BTreeMap<UserId, Vec<RoomId>>);

View File

@ -19,10 +19,18 @@ use serde::{
/// this *m.dummy* event as the most recent event and using the keyshare request to set up the /// this *m.dummy* event as the most recent event and using the keyshare request to set up the
/// session. The keyshare request and *m.dummy* combination should result in the original sending /// session. The keyshare request and *m.dummy* combination should result in the original sending
/// client receiving keys over the newly established session. /// client receiving keys over the newly established session.
#[derive(Clone, Debug, EventContent)] #[derive(Clone, Debug, Default, EventContent)]
#[allow(clippy::exhaustive_structs)]
#[ruma_event(type = "m.dummy", kind = ToDevice)] #[ruma_event(type = "m.dummy", kind = ToDevice)]
pub struct DummyToDeviceEventContent; pub struct DummyToDeviceEventContent;
impl DummyToDeviceEventContent {
/// Create a new `DummyToDeviceEventContent`.
pub fn new() -> Self {
Self
}
}
impl<'de> Deserialize<'de> for DummyToDeviceEventContent { impl<'de> Deserialize<'de> for DummyToDeviceEventContent {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where where

View File

@ -17,6 +17,7 @@ impl Error for InvalidInput {}
/// An error when attempting to create a value from a string via the `FromStr` trait. /// An error when attempting to create a value from a string via the `FromStr` trait.
#[derive(Clone, Eq, Debug, Hash, PartialEq)] #[derive(Clone, Eq, Debug, Hash, PartialEq)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct FromStrError; pub struct FromStrError;
impl fmt::Display for FromStrError { impl fmt::Display for FromStrError {

View File

@ -1,3 +1,5 @@
#![allow(clippy::exhaustive_structs)]
use ruma_common::MilliSecondsSinceUnixEpoch; use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_events_macros::Event; use ruma_events_macros::Event;
use ruma_identifiers::{EventId, RoomId, UserId}; use ruma_identifiers::{EventId, RoomId, UserId};

View File

@ -48,6 +48,7 @@ pub struct ForwardedRoomKeyToDeviceEventContent {
/// This struct will not be updated even if additional fields are added to `ConditionalPushRule` in /// This struct will not be updated even if additional fields are added to `ConditionalPushRule` in
/// a new (non-breaking) release of the Matrix specification. /// a new (non-breaking) release of the Matrix specification.
#[derive(Debug)] #[derive(Debug)]
#[allow(clippy::exhaustive_structs)]
pub struct ForwardedRoomKeyToDeviceEventContentInit { pub struct ForwardedRoomKeyToDeviceEventContentInit {
/// The encryption algorithm the key in this event is to be used with. /// The encryption algorithm the key in this event is to be used with.
pub algorithm: EventEncryptionAlgorithm, pub algorithm: EventEncryptionAlgorithm,

View File

@ -83,6 +83,7 @@ pub enum AcceptMethod {
/// Method specific content of a unknown key verification method. /// Method specific content of a unknown key verification method.
#[doc(hidden)] #[doc(hidden)]
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[allow(clippy::exhaustive_structs)]
pub struct _CustomContent { pub struct _CustomContent {
/// The name of the method. /// The name of the method.
pub method: String, pub method: String,
@ -124,6 +125,7 @@ pub struct SasV1Content {
/// Mandatory initial set of fields for creating an accept `SasV1Content`. /// Mandatory initial set of fields for creating an accept `SasV1Content`.
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize)]
#[allow(clippy::exhaustive_structs)]
pub struct SasV1ContentInit { pub struct SasV1ContentInit {
/// The key agreement protocol the device is choosing to use, out of the /// The key agreement protocol the device is choosing to use, out of the
/// options in the *m.key.verification.start* message. /// options in the *m.key.verification.start* message.

View File

@ -15,6 +15,7 @@ pub type KeyEvent = MessageEvent<KeyEventContent>;
/// The payload for a to-device `KeyEvent`. /// The payload for a to-device `KeyEvent`.
#[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.key.verification.key", kind = ToDevice)] #[ruma_event(type = "m.key.verification.key", kind = ToDevice)]
pub struct KeyToDeviceEventContent { pub struct KeyToDeviceEventContent {
/// An opaque identifier for the verification process. /// An opaque identifier for the verification process.

View File

@ -45,9 +45,10 @@ impl MacToDeviceEventContent {
/// The payload for an in-room `MacEvent`. /// The payload for an in-room `MacEvent`.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[ruma_event(type = "m.key.verification.mac", kind = Message)]
#[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)]
#[ruma_event(type = "m.key.verification.mac", kind = Message)]
pub struct MacEventContent { pub struct MacEventContent {
/// A map of the key ID to the MAC of the key, using the algorithm in the verification process. /// A map of the key ID to the MAC of the key, using the algorithm in the verification process.
/// ///

View File

@ -100,6 +100,7 @@ pub enum StartMethod {
/// Method specific content of a unknown key verification method. /// Method specific content of a unknown key verification method.
#[doc(hidden)] #[doc(hidden)]
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[allow(clippy::exhaustive_structs)]
pub struct _CustomContent { pub struct _CustomContent {
/// The name of the method. /// The name of the method.
pub method: String, pub method: String,
@ -158,6 +159,7 @@ pub struct SasV1Content {
/// Mandatory initial set of fields for creating an `SasV1Content`. /// Mandatory initial set of fields for creating an `SasV1Content`.
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize)]
#[allow(clippy::exhaustive_structs)]
pub struct SasV1ContentInit { pub struct SasV1ContentInit {
/// The key agreement protocols the sending device understands. /// The key agreement protocols the sending device understands.
/// ///

View File

@ -195,6 +195,7 @@ pub use self::{
/// Extra information about an event that is not incorporated into the event's /// Extra information about an event that is not incorporated into the event's
/// hash. /// hash.
#[derive(Clone, Debug, Default, Deserialize, Serialize)] #[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct Unsigned { pub struct Unsigned {
/// The time in milliseconds that has elapsed since the event was sent. This /// The time in milliseconds that has elapsed since the event was sent. This
/// field is generated by the local homeserver, and may be incorrect if the /// field is generated by the local homeserver, and may be incorrect if the
@ -216,6 +217,11 @@ pub struct Unsigned {
} }
impl Unsigned { impl Unsigned {
/// Create a new `Unsigned` with fields set to `None`.
pub fn new() -> Self {
Self::default()
}
/// Whether this unsigned data is empty (all fields are `None`). /// Whether this unsigned data is empty (all fields are `None`).
/// ///
/// This method is used to determine whether to skip serializing the /// This method is used to determine whether to skip serializing the
@ -230,6 +236,7 @@ impl Unsigned {
/// Extra information about a redacted event that is not incorporated into the event's /// Extra information about a redacted event that is not incorporated into the event's
/// hash. /// hash.
#[derive(Clone, Debug, Default, Deserialize, Serialize)] #[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct RedactedUnsigned { pub struct RedactedUnsigned {
/// The event that redacted this event, if any. /// The event that redacted this event, if any.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@ -237,6 +244,16 @@ pub struct RedactedUnsigned {
} }
impl RedactedUnsigned { impl RedactedUnsigned {
/// Create a new `RedactedUnsigned` with field set to `None`.
pub fn new() -> Self {
Self::default()
}
/// Create a new `RedactedUnsigned` with the given redacted because.
pub fn new_because(redacted_because: Box<SyncRedactionEvent>) -> Self {
Self { redacted_because: Some(redacted_because) }
}
/// Whether this unsigned data is empty (`redacted_because` is `None`). /// Whether this unsigned data is empty (`redacted_because` is `None`).
/// ///
/// This method is used to determine whether to skip serializing the /// This method is used to determine whether to skip serializing the
@ -366,6 +383,7 @@ pub enum HasDeserializeFields {
/// Helper struct to determine if the event has been redacted. /// Helper struct to determine if the event has been redacted.
#[doc(hidden)] #[doc(hidden)]
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
#[allow(clippy::exhaustive_structs)]
pub struct UnsignedDeHelper { pub struct UnsignedDeHelper {
/// This is the field that signals an event has been redacted. /// This is the field that signals an event has been redacted.
pub redacted_because: Option<IgnoredAny>, pub redacted_because: Option<IgnoredAny>,
@ -374,6 +392,7 @@ pub struct UnsignedDeHelper {
/// Helper struct to determine the event kind from a `serde_json::value::RawValue`. /// Helper struct to determine the event kind from a `serde_json::value::RawValue`.
#[doc(hidden)] #[doc(hidden)]
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
#[allow(clippy::exhaustive_structs)]
pub struct EventDeHelper { pub struct EventDeHelper {
/// the Matrix event type string "m.room.whatever". /// the Matrix event type string "m.room.whatever".
#[serde(rename = "type")] #[serde(rename = "type")]

View File

@ -20,6 +20,7 @@ use crate::EventType;
/// Enum for PDU schemas /// Enum for PDU schemas
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[serde(untagged)] #[serde(untagged)]
pub enum Pdu { pub enum Pdu {
/// PDU for room versions 1 and 2. /// PDU for room versions 1 and 2.
@ -31,6 +32,7 @@ pub enum Pdu {
/// A 'persistent data unit' (event) for room versions 1 and 2. /// A 'persistent data unit' (event) for room versions 1 and 2.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[allow(clippy::exhaustive_structs)]
pub struct RoomV1Pdu { pub struct RoomV1Pdu {
/// Event ID for the PDU. /// Event ID for the PDU.
pub event_id: EventId, pub event_id: EventId,
@ -93,6 +95,7 @@ pub struct RoomV1Pdu {
/// A 'persistent data unit' (event) for room versions 3 and beyond. /// A 'persistent data unit' (event) for room versions 3 and beyond.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[allow(clippy::exhaustive_structs)]
pub struct RoomV3Pdu { pub struct RoomV3Pdu {
/// The room this event belongs to. /// The room this event belongs to.
pub room_id: RoomId, pub room_id: RoomId,
@ -150,7 +153,15 @@ pub struct RoomV3Pdu {
/// Content hashes of a PDU. /// Content hashes of a PDU.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct EventHash { pub struct EventHash {
/// The SHA-256 hash. /// The SHA-256 hash.
pub sha256: String, pub sha256: String,
} }
impl EventHash {
/// Create a new `EventHash` with the given SHA256 hash.
pub fn new(sha256: String) -> Self {
Self { sha256 }
}
}

View File

@ -10,6 +10,7 @@ pub type RoomEvent = StateEvent<RoomEventContent>;
/// The payload for `RoomEvent`. /// The payload for `RoomEvent`.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[allow(clippy::exhaustive_structs)]
#[ruma_event(type = "m.policy.rule.room", kind = State)] #[ruma_event(type = "m.policy.rule.room", kind = State)]
pub struct RoomEventContent(pub PolicyRuleEventContent); pub struct RoomEventContent(pub PolicyRuleEventContent);

View File

@ -10,5 +10,6 @@ pub type ServerEvent = StateEvent<ServerEventContent>;
/// The payload for `ServerEvent`. /// The payload for `ServerEvent`.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[allow(clippy::exhaustive_structs)]
#[ruma_event(type = "m.policy.rule.server", kind = State)] #[ruma_event(type = "m.policy.rule.server", kind = State)]
pub struct ServerEventContent(pub PolicyRuleEventContent); pub struct ServerEventContent(pub PolicyRuleEventContent);

View File

@ -10,5 +10,6 @@ pub type UserEvent = StateEvent<UserEventContent>;
/// The payload for `UserEvent`. /// The payload for `UserEvent`.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[allow(clippy::exhaustive_structs)]
#[ruma_event(type = "m.policy.rule.user", kind = State)] #[ruma_event(type = "m.policy.rule.user", kind = State)]
pub struct UserEventContent(pub PolicyRuleEventContent); pub struct UserEventContent(pub PolicyRuleEventContent);

View File

@ -10,6 +10,7 @@ use serde::{Deserialize, Serialize};
/// Presence event. /// Presence event.
#[derive(Clone, Debug, Event)] #[derive(Clone, Debug, Event)]
#[allow(clippy::exhaustive_structs)]
pub struct PresenceEvent { pub struct PresenceEvent {
/// Data specific to the event type. /// Data specific to the event type.
pub content: PresenceEventContent, pub content: PresenceEventContent,

View File

@ -20,6 +20,7 @@ pub type ReceiptEvent = EphemeralRoomEvent<ReceiptEventContent>;
/// A mapping of event ID to a collection of receipts for this event ID. The event ID is the ID of /// A mapping of event ID to a collection of receipts for this event ID. The event ID is the ID of
/// the event being acknowledged and *not* an ID for the receipt itself. /// the event being acknowledged and *not* an ID for the receipt itself.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[allow(clippy::exhaustive_structs)]
#[ruma_event(type = "m.receipt", kind = EphemeralRoom)] #[ruma_event(type = "m.receipt", kind = EphemeralRoom)]
pub struct ReceiptEventContent(pub BTreeMap<EventId, Receipts>); pub struct ReceiptEventContent(pub BTreeMap<EventId, Receipts>);

View File

@ -55,7 +55,7 @@ pub struct AnnotationChunk {
} }
impl AnnotationChunk { impl AnnotationChunk {
/// Creates a new `AnnotationChunk`. /// Creates a new `AnnotationChunk` with the given chunk and next batch token.
pub fn new(chunk: Vec<BundledAnnotation>, next_batch: Option<String>) -> Self { pub fn new(chunk: Vec<BundledAnnotation>, next_batch: Option<String>) -> Self {
Self { chunk, next_batch } Self { chunk, next_batch }
} }
@ -71,7 +71,7 @@ pub struct Relations {
} }
impl Relations { impl Relations {
/// Creates a new `Relations` struct. /// Creates a new `Relations` with the given annotation.
pub fn new(annotation: Option<AnnotationChunk>) -> Self { pub fn new(annotation: Option<AnnotationChunk>) -> Self {
Self { annotation } Self { annotation }
} }

View File

@ -135,6 +135,7 @@ pub struct EncryptedFile {
/// ///
/// This struct will not be updated even if additional fields are added to `EncryptedFile` in a new /// This struct will not be updated even if additional fields are added to `EncryptedFile` in a new
/// (non-breaking) release of the Matrix specification. /// (non-breaking) release of the Matrix specification.
#[allow(clippy::exhaustive_structs)]
pub struct EncryptedFileInit { pub struct EncryptedFileInit {
/// The URL to the file. /// The URL to the file.
pub url: MxcUri, pub url: MxcUri,
@ -188,6 +189,7 @@ pub struct JsonWebKey {
/// ///
/// This struct will not be updated even if additional fields are added to `JsonWebKey` in a new /// This struct will not be updated even if additional fields are added to `JsonWebKey` in a new
/// (non-breaking) release of the Matrix specification. /// (non-breaking) release of the Matrix specification.
#[allow(clippy::exhaustive_structs)]
pub struct JsonWebKeyInit { pub struct JsonWebKeyInit {
/// Key type. Must be `oct`. /// Key type. Must be `oct`.
pub kty: String, pub kty: String,

View File

@ -49,7 +49,8 @@ impl RedactContent for AliasesEventContent {
} }
/// An aliases event that has been redacted. /// An aliases event that has been redacted.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct RedactedAliasesEventContent { pub struct RedactedAliasesEventContent {
/// A list of room aliases. /// A list of room aliases.
/// ///
@ -58,6 +59,22 @@ pub struct RedactedAliasesEventContent {
pub aliases: Option<Vec<RoomAliasId>>, pub aliases: Option<Vec<RoomAliasId>>,
} }
impl RedactedAliasesEventContent {
/// Create a `RedactedAliasesEventContent` with the given aliases.
///
/// This is only valid for room version 5 and below.
pub fn new_v1(aliases: Vec<RoomAliasId>) -> Self {
Self { aliases: Some(aliases) }
}
/// Create a `RedactedAliasesEventContent` with the given aliases.
///
/// This is only valid for room version 6 and above.
pub fn new_v6() -> Self {
Self::default()
}
}
impl EventContent for RedactedAliasesEventContent { impl EventContent for RedactedAliasesEventContent {
fn event_type(&self) -> &str { fn event_type(&self) -> &str {
"m.room.aliases" "m.room.aliases"

View File

@ -55,7 +55,8 @@ impl AvatarEventContent {
} }
/// Metadata about an image (specific to avatars). /// Metadata about an image (specific to avatars).
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct ImageInfo { pub struct ImageInfo {
/// The height of the image in pixels. /// The height of the image in pixels.
#[serde(rename = "h", skip_serializing_if = "Option::is_none")] #[serde(rename = "h", skip_serializing_if = "Option::is_none")]
@ -91,3 +92,10 @@ pub struct ImageInfo {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub blurhash: Option<String>, pub blurhash: Option<String>,
} }
impl ImageInfo {
/// Create a new `ImageInfo` with all fields set to `None`.
pub fn new() -> Self {
Self::default()
}
}

View File

@ -125,6 +125,7 @@ pub struct MegolmV1AesSha2Content {
/// This struct will not be updated even if additional fields are added to `MegolmV1AesSha2Content` /// This struct will not be updated even if additional fields are added to `MegolmV1AesSha2Content`
/// in a new (non-breaking) release of the Matrix specification. /// in a new (non-breaking) release of the Matrix specification.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
#[allow(clippy::exhaustive_structs)]
pub struct MegolmV1AesSha2ContentInit { pub struct MegolmV1AesSha2ContentInit {
/// The encrypted content of the event. /// The encrypted content of the event.
pub ciphertext: String, pub ciphertext: String,

View File

@ -643,6 +643,7 @@ impl MessageFormat {
/// Common message event content fields for message types that have separate plain-text and /// Common message event content fields for message types that have separate plain-text and
/// formatted representations. /// formatted representations.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[allow(clippy::exhaustive_structs)]
pub struct FormattedBody { pub struct FormattedBody {
/// The format used in the `formatted_body`. /// The format used in the `formatted_body`.
pub format: MessageFormat, pub format: MessageFormat,

View File

@ -9,6 +9,7 @@ use crate::Unsigned;
/// Redaction event. /// Redaction event.
#[derive(Clone, Debug, Event)] #[derive(Clone, Debug, Event)]
#[allow(clippy::exhaustive_structs)]
pub struct RedactionEvent { pub struct RedactionEvent {
/// Data specific to the event type. /// Data specific to the event type.
pub content: RedactionEventContent, pub content: RedactionEventContent,
@ -34,6 +35,7 @@ pub struct RedactionEvent {
/// Redaction event without a `room_id`. /// Redaction event without a `room_id`.
#[derive(Clone, Debug, Event)] #[derive(Clone, Debug, Event)]
#[allow(clippy::exhaustive_structs)]
pub struct SyncRedactionEvent { pub struct SyncRedactionEvent {
/// Data specific to the event type. /// Data specific to the event type.
pub content: RedactionEventContent, pub content: RedactionEventContent,

View File

@ -45,6 +45,7 @@ pub enum Relation {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
#[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 ID of the event being replacing. /// The ID of the event being replacing.
pub event_id: EventId, pub event_id: EventId,

View File

@ -63,6 +63,7 @@ impl FromStr for UserTagName {
/// An error returned when attempting to create a UserTagName with a string that would make it /// An error returned when attempting to create a UserTagName with a string that would make it
/// invalid. /// invalid.
#[derive(Debug)] #[derive(Debug)]
#[allow(clippy::exhaustive_structs)]
pub struct InvalidUserTagName; pub struct InvalidUserTagName;
impl fmt::Display for InvalidUserTagName { impl fmt::Display for InvalidUserTagName {

View File

@ -34,16 +34,16 @@ fn serialize_pdu_as_v1() {
state_key: Some("state".into()), state_key: Some("state".into()),
prev_events: vec![( prev_events: vec![(
event_id!("$previousevent:matrix.org"), event_id!("$previousevent:matrix.org"),
EventHash { sha256: "123567".into() }, EventHash::new("123567".into()),
)], )],
depth: 2_u32.into(), depth: 2_u32.into(),
auth_events: vec![( auth_events: vec![(
event_id!("$someauthevent:matrix.org"), event_id!("$someauthevent:matrix.org"),
EventHash { sha256: "21389CFEDABC".into() }, EventHash::new("21389CFEDABC".into()),
)], )],
redacts: Some(event_id!("$9654:matrix.org")), redacts: Some(event_id!("$9654:matrix.org")),
unsigned, unsigned,
hashes: EventHash { sha256: "1233543bABACDEF".into() }, hashes: EventHash::new("1233543bABACDEF".into()),
signatures, signatures,
}; };
let pdu = Pdu::RoomV1Pdu(v1_pdu); let pdu = Pdu::RoomV1Pdu(v1_pdu);
@ -103,7 +103,7 @@ fn serialize_pdu_as_v3() {
auth_events: vec![event_id!("$someauthevent:matrix.org")], auth_events: vec![event_id!("$someauthevent:matrix.org")],
redacts: Some(event_id!("$9654:matrix.org")), redacts: Some(event_id!("$9654:matrix.org")),
unsigned, unsigned,
hashes: EventHash { sha256: "1233543bABACDEF".into() }, hashes: EventHash::new("1233543bABACDEF".into()),
signatures, signatures,
}; };
let pdu_stub = Pdu::RoomV3Pdu(v3_pdu); let pdu_stub = Pdu::RoomV3Pdu(v3_pdu);
@ -188,6 +188,8 @@ fn deserialize_pdu_as_v1() {
); );
} }
Pdu::RoomV3Pdu(_) => panic!("Matched V3 PDU"), Pdu::RoomV3Pdu(_) => panic!("Matched V3 PDU"),
#[cfg(not(feature = "unstable-exhaustive-types"))]
_ => unreachable!("new PDU version"),
} }
} }
@ -233,5 +235,7 @@ fn deserialize_pdu_as_v3() {
Pdu::RoomV3Pdu(v3_pdu) => { Pdu::RoomV3Pdu(v3_pdu) => {
assert_eq!(v3_pdu.auth_events.first().unwrap(), &event_id!("$abc123:matrix.org")); assert_eq!(v3_pdu.auth_events.first().unwrap(), &event_id!("$abc123:matrix.org"));
} }
#[cfg(not(feature = "unstable-exhaustive-types"))]
_ => unreachable!("new PDU version"),
} }
} }

View File

@ -38,7 +38,7 @@ fn unsigned() -> RedactedUnsigned {
#[test] #[test]
fn redacted_message_event_serialize() { fn redacted_message_event_serialize() {
let redacted = RedactedSyncMessageEvent { let redacted = RedactedSyncMessageEvent {
content: RedactedMessageEventContent, content: RedactedMessageEventContent::new(),
event_id: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"),
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
sender: user_id!("@carl:example.com"), sender: user_id!("@carl:example.com"),
@ -59,7 +59,7 @@ fn redacted_message_event_serialize() {
#[test] #[test]
fn redacted_aliases_event_serialize_no_content() { fn redacted_aliases_event_serialize_no_content() {
let redacted = RedactedSyncStateEvent { let redacted = RedactedSyncStateEvent {
content: RedactedAliasesEventContent { aliases: None }, content: RedactedAliasesEventContent::default(),
event_id: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"),
state_key: "".into(), state_key: "".into(),
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
@ -82,7 +82,7 @@ fn redacted_aliases_event_serialize_no_content() {
#[test] #[test]
fn redacted_aliases_event_serialize_with_content() { fn redacted_aliases_event_serialize_with_content() {
let redacted = RedactedSyncStateEvent { let redacted = RedactedSyncStateEvent {
content: RedactedAliasesEventContent { aliases: Some(vec![]) }, content: RedactedAliasesEventContent::new_v1(vec![]),
event_id: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"),
state_key: "".to_owned(), state_key: "".to_owned(),
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
@ -125,7 +125,7 @@ fn redacted_aliases_deserialize() {
.unwrap(), .unwrap(),
AnySyncRoomEvent::RedactedState(AnyRedactedSyncStateEvent::RoomAliases( AnySyncRoomEvent::RedactedState(AnyRedactedSyncStateEvent::RoomAliases(
RedactedSyncStateEvent { RedactedSyncStateEvent {
content: RedactedAliasesEventContent { aliases }, content: RedactedAliasesEventContent { aliases, .. },
event_id, event_id,
.. ..
}, },
@ -153,7 +153,7 @@ fn redacted_deserialize_any_room() {
.deserialize() .deserialize()
.unwrap(), .unwrap(),
AnyRoomEvent::RedactedMessage(AnyRedactedMessageEvent::RoomMessage(RedactedMessageEvent { AnyRoomEvent::RedactedMessage(AnyRedactedMessageEvent::RoomMessage(RedactedMessageEvent {
content: RedactedMessageEventContent, content: RedactedMessageEventContent { .. },
event_id, room_id, .. event_id, room_id, ..
})) if event_id == event_id!("$h29iv0s8:example.com") })) if event_id == event_id!("$h29iv0s8:example.com")
&& room_id == room_id!("!roomid:room.com") && room_id == room_id!("!roomid:room.com")
@ -192,7 +192,7 @@ fn redacted_deserialize_any_room_sync() {
.unwrap(), .unwrap(),
AnySyncRoomEvent::RedactedMessage(AnyRedactedSyncMessageEvent::RoomMessage( AnySyncRoomEvent::RedactedMessage(AnyRedactedSyncMessageEvent::RoomMessage(
RedactedSyncMessageEvent { RedactedSyncMessageEvent {
content: RedactedMessageEventContent, content: RedactedMessageEventContent { .. },
event_id, event_id,
.. ..
} }
@ -222,7 +222,7 @@ fn redacted_state_event_deserialize() {
AnySyncRoomEvent::RedactedState(AnyRedactedSyncStateEvent::RoomCreate( AnySyncRoomEvent::RedactedState(AnyRedactedSyncStateEvent::RoomCreate(
RedactedSyncStateEvent { RedactedSyncStateEvent {
content: RedactedCreateEventContent { content: RedactedCreateEventContent {
creator, creator, ..
}, },
event_id, event_id,
state_key, state_key,
@ -311,7 +311,7 @@ fn redact_method_properly_redacts() {
assert_matches!( assert_matches!(
event.redact(redaction, &RoomVersionId::Version6), event.redact(redaction, &RoomVersionId::Version6),
AnyRedactedMessageEvent::RoomMessage(RedactedMessageEvent { AnyRedactedMessageEvent::RoomMessage(RedactedMessageEvent {
content: RedactedMessageEventContent, content: RedactedMessageEventContent { .. },
event_id, event_id,
room_id, room_id,
sender, sender,
@ -338,7 +338,7 @@ fn redact_message_content() {
assert_matches!( assert_matches!(
content.redact(&RoomVersionId::Version6), content.redact(&RoomVersionId::Version6),
AnyRedactedMessageEventContent::RoomMessage(RedactedMessageEventContent) AnyRedactedMessageEventContent::RoomMessage(RedactedMessageEventContent { .. })
); );
} }
@ -356,7 +356,8 @@ fn redact_state_content() {
assert_matches!( assert_matches!(
content.redact(&RoomVersionId::Version6), content.redact(&RoomVersionId::Version6),
AnyRedactedStateEventContent::RoomCreate(RedactedCreateEventContent { AnyRedactedStateEventContent::RoomCreate(RedactedCreateEventContent {
creator creator,
..
}) if creator == user_id!("@carl:example.com") }) if creator == user_id!("@carl:example.com")
); );
} }

View File

@ -277,7 +277,7 @@ fn edit_deserialization_future() {
formatted: None, formatted: None,
.. ..
}), }),
relates_to: Some(Relation::Replacement(Replacement { event_id, new_content })), relates_to: Some(Relation::Replacement(Replacement { event_id, new_content, .. })),
.. ..
} if body == "s/foo/bar" } if body == "s/foo/bar"
&& event_id == ev_id && event_id == ev_id
@ -321,6 +321,7 @@ fn verification_request_deserialization() {
to, to,
from_device, from_device,
methods, methods,
..
}), }),
.. ..
} if body == "@example:localhost is requesting to verify your key, ..." } if body == "@example:localhost is requesting to verify your key, ..."
@ -351,12 +352,9 @@ fn verification_request_serialization() {
"methods": methods "methods": methods
}); });
let content = MessageType::VerificationRequest(KeyVerificationRequestEventContent { let content = MessageType::VerificationRequest(KeyVerificationRequestEventContent::new(
to: user_id, body, methods, device_id, user_id,
from_device: device_id, ));
body,
methods,
});
assert_eq!(to_json_value(&content).unwrap(), json_data,); assert_eq!(to_json_value(&content).unwrap(), json_data,);
} }