client-api: Make structs in sync_events non-exhaustive
This commit is contained in:
parent
8b362e4b63
commit
647f56e0a1
@ -160,6 +160,7 @@ impl<'a> From<&'a str> for Filter<'a> {
|
|||||||
|
|
||||||
/// Updates to rooms.
|
/// Updates to rooms.
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct Rooms {
|
pub struct Rooms {
|
||||||
/// The rooms that the user has left or been banned from.
|
/// The rooms that the user has left or been banned from.
|
||||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||||
@ -175,6 +176,11 @@ pub struct Rooms {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Rooms {
|
impl Rooms {
|
||||||
|
/// Creates an empty `Rooms`.
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns true if there is no update in any room.
|
/// Returns true if there is no update in any room.
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.leave.is_empty() && self.join.is_empty() && self.invite.is_empty()
|
self.leave.is_empty() && self.join.is_empty() && self.invite.is_empty()
|
||||||
@ -182,7 +188,8 @@ impl Rooms {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Historical updates to left rooms.
|
/// Historical updates to left rooms.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct LeftRoom {
|
pub struct LeftRoom {
|
||||||
/// The timeline of messages and state changes in the room up to the point when the user
|
/// The timeline of messages and state changes in the room up to the point when the user
|
||||||
/// left.
|
/// left.
|
||||||
@ -199,6 +206,11 @@ pub struct LeftRoom {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl LeftRoom {
|
impl LeftRoom {
|
||||||
|
/// Creates an empty `LeftRoom`.
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns true if there are updates in the room.
|
/// Returns true if there are updates in the room.
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.timeline.is_empty() && self.state.is_empty() && self.account_data.is_empty()
|
self.timeline.is_empty() && self.state.is_empty() && self.account_data.is_empty()
|
||||||
@ -206,7 +218,8 @@ impl LeftRoom {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Updates to joined rooms.
|
/// Updates to joined rooms.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct JoinedRoom {
|
pub struct JoinedRoom {
|
||||||
/// Information about the room which clients may need to correctly render it
|
/// Information about the room which clients may need to correctly render it
|
||||||
/// to users.
|
/// to users.
|
||||||
@ -238,6 +251,11 @@ pub struct JoinedRoom {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl JoinedRoom {
|
impl JoinedRoom {
|
||||||
|
/// Creates an empty `JoinedRoom`.
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns true if there are no updates in the room.
|
/// Returns true if there are no updates in the room.
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.summary.is_empty()
|
self.summary.is_empty()
|
||||||
@ -251,6 +269,7 @@ impl JoinedRoom {
|
|||||||
|
|
||||||
/// unread notifications count
|
/// unread notifications count
|
||||||
#[derive(Clone, Copy, Default, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Copy, Default, Debug, Deserialize, Serialize)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct UnreadNotificationsCount {
|
pub struct UnreadNotificationsCount {
|
||||||
/// The number of unread notifications for this room with the highlight flag set.
|
/// The number of unread notifications for this room with the highlight flag set.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
@ -262,6 +281,11 @@ pub struct UnreadNotificationsCount {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl UnreadNotificationsCount {
|
impl UnreadNotificationsCount {
|
||||||
|
/// Creates an empty `UnreadNotificationsCount`.
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns true if there are no notification count updates.
|
/// Returns true if there are no notification count updates.
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.highlight_count.is_none() && self.notification_count.is_none()
|
self.highlight_count.is_none() && self.notification_count.is_none()
|
||||||
@ -270,6 +294,7 @@ impl UnreadNotificationsCount {
|
|||||||
|
|
||||||
/// Events in the room.
|
/// Events in the room.
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct Timeline {
|
pub struct Timeline {
|
||||||
/// True if the number of events returned was limited by the `limit` on the filter.
|
/// True if the number of events returned was limited by the `limit` on the filter.
|
||||||
#[serde(default, skip_serializing_if = "ruma_serde::is_default")]
|
#[serde(default, skip_serializing_if = "ruma_serde::is_default")]
|
||||||
@ -286,6 +311,11 @@ pub struct Timeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Timeline {
|
impl Timeline {
|
||||||
|
/// Creates an empty `Timeline`.
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns true if there are no timeline updates.
|
/// Returns true if there are no timeline updates.
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.events.is_empty()
|
self.events.is_empty()
|
||||||
@ -294,6 +324,7 @@ impl Timeline {
|
|||||||
|
|
||||||
/// State events in the room.
|
/// State events in the room.
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct State {
|
pub struct State {
|
||||||
/// A list of state events.
|
/// A list of state events.
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||||
@ -301,6 +332,11 @@ pub struct State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
|
/// Creates an empty `State`.
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns true if there are no state updates.
|
/// Returns true if there are no state updates.
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.events.is_empty()
|
self.events.is_empty()
|
||||||
@ -309,6 +345,7 @@ impl State {
|
|||||||
|
|
||||||
/// The private data that this user has attached to this room.
|
/// The private data that this user has attached to this room.
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct AccountData {
|
pub struct AccountData {
|
||||||
/// A list of events.
|
/// A list of events.
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||||
@ -316,6 +353,11 @@ pub struct AccountData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AccountData {
|
impl AccountData {
|
||||||
|
/// Creates an empty `AccountData`.
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns true if there are no account data updates.
|
/// Returns true if there are no account data updates.
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.events.is_empty()
|
self.events.is_empty()
|
||||||
@ -324,6 +366,7 @@ impl AccountData {
|
|||||||
|
|
||||||
/// Ephemeral events not recorded in the timeline or state of the room.
|
/// Ephemeral events not recorded in the timeline or state of the room.
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct Ephemeral {
|
pub struct Ephemeral {
|
||||||
/// A list of events.
|
/// A list of events.
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||||
@ -331,6 +374,11 @@ pub struct Ephemeral {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Ephemeral {
|
impl Ephemeral {
|
||||||
|
/// Creates an empty `Ephemeral`.
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns true if there are no ephemeral event updates.
|
/// Returns true if there are no ephemeral event updates.
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.events.is_empty()
|
self.events.is_empty()
|
||||||
@ -339,6 +387,7 @@ impl Ephemeral {
|
|||||||
|
|
||||||
/// Information about room for rendering to clients.
|
/// Information about room for rendering to clients.
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct RoomSummary {
|
pub struct RoomSummary {
|
||||||
/// Users which can be used to generate a room name if the room does not have
|
/// Users which can be used to generate a room name if the room does not have
|
||||||
/// one. Required if room name or canonical aliases are not set or empty.
|
/// one. Required if room name or canonical aliases are not set or empty.
|
||||||
@ -359,6 +408,11 @@ pub struct RoomSummary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl RoomSummary {
|
impl RoomSummary {
|
||||||
|
/// Creates an empty `RoomSummary`.
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns true if there are no room summary updates.
|
/// Returns true if there are no room summary updates.
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.heroes.is_empty()
|
self.heroes.is_empty()
|
||||||
@ -368,7 +422,8 @@ impl RoomSummary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Updates to the rooms that the user has been invited to.
|
/// Updates to the rooms that the user has been invited to.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct InvitedRoom {
|
pub struct InvitedRoom {
|
||||||
/// The state of a room that the user has been invited to.
|
/// The state of a room that the user has been invited to.
|
||||||
#[serde(default, skip_serializing_if = "InviteState::is_empty")]
|
#[serde(default, skip_serializing_if = "InviteState::is_empty")]
|
||||||
@ -376,6 +431,11 @@ pub struct InvitedRoom {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl InvitedRoom {
|
impl InvitedRoom {
|
||||||
|
/// Creates an empty `InvitedRoom`.
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns true if there are no updates to this room.
|
/// Returns true if there are no updates to this room.
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.invite_state.is_empty()
|
self.invite_state.is_empty()
|
||||||
@ -384,6 +444,7 @@ impl InvitedRoom {
|
|||||||
|
|
||||||
/// The state of a room that the user has been invited to.
|
/// The state of a room that the user has been invited to.
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct InviteState {
|
pub struct InviteState {
|
||||||
/// A list of state events.
|
/// A list of state events.
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||||
@ -391,6 +452,11 @@ pub struct InviteState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl InviteState {
|
impl InviteState {
|
||||||
|
/// Creates an empty `InviteState`.
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns true if there are no state updates.
|
/// Returns true if there are no state updates.
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.events.is_empty()
|
self.events.is_empty()
|
||||||
@ -399,6 +465,7 @@ impl InviteState {
|
|||||||
|
|
||||||
/// Updates to the presence status of other users.
|
/// Updates to the presence status of other users.
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct Presence {
|
pub struct Presence {
|
||||||
/// A list of events.
|
/// A list of events.
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||||
@ -406,6 +473,11 @@ pub struct Presence {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Presence {
|
impl Presence {
|
||||||
|
/// Creates an empty `Presence`.
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns true if there are no presence updates.
|
/// Returns true if there are no presence updates.
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.events.is_empty()
|
self.events.is_empty()
|
||||||
@ -414,6 +486,7 @@ impl Presence {
|
|||||||
|
|
||||||
/// Messages sent dirrectly between devices.
|
/// Messages sent dirrectly between devices.
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct ToDevice {
|
pub struct ToDevice {
|
||||||
/// A list of to-device events.
|
/// A list of to-device events.
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||||
@ -421,6 +494,11 @@ pub struct ToDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ToDevice {
|
impl ToDevice {
|
||||||
|
/// Creates an empty `ToDevice`.
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns true if there are no to-device events.
|
/// Returns true if there are no to-device events.
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.events.is_empty()
|
self.events.is_empty()
|
||||||
@ -429,6 +507,7 @@ impl ToDevice {
|
|||||||
|
|
||||||
/// Information on E2E device udpates.
|
/// Information on E2E device udpates.
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct DeviceLists {
|
pub struct DeviceLists {
|
||||||
/// List of users who have updated their device identity keys or who now
|
/// List of users who have updated their device identity keys or who now
|
||||||
/// share an encrypted room with the client since the previous sync
|
/// share an encrypted room with the client since the previous sync
|
||||||
@ -442,6 +521,11 @@ pub struct DeviceLists {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl DeviceLists {
|
impl DeviceLists {
|
||||||
|
/// Creates an empty `DeviceLists`.
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns true if there are no device list updates.
|
/// Returns true if there are no device list updates.
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.changed.is_empty() && self.left.is_empty()
|
self.changed.is_empty() && self.left.is_empty()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user