Skip to content

Commit 80bf57e

Browse files
committed
fix: Mark StringEnums as non-exhaustive
Because of the private variant, which shouldn't be matched, they should never be exhaustive.
1 parent 5c23e48 commit 80bf57e

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Breaking changes:
44

55
* The list_room response changes the fields `version`, `join_rules`, `guest_access` and `history_visibility` to be an option
66
* The list_room response changes the `join_rules` field to be `Option<SpaceRoomJoinRule>`
7+
* `background_update::run::v1::JobName` is now non-exhaustive.
8+
* `RoomSortOrder` and `RoomDirection` in `rooms::list_rooms::v1` are now non-
9+
exhaustive. Their `PartialOrd` and `Ord` implementations now use their string
10+
representation instead of the order in which they are defined in the enum.
711

812
Improvement:
913

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ cloned_instead_of_copied = "warn"
4242
dbg_macro = "warn"
4343
disallowed_types = "warn"
4444
empty_line_after_outer_attr = "warn"
45-
# exhaustive_enums = "warn"
45+
exhaustive_enums = "warn"
4646
# exhaustive_structs = "warn"
4747
inefficient_to_string = "warn"
4848
macro_use_imports = "warn"

src/background_updates/run/v1.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use ruma::{
44
api::{request, response, Metadata},
55
metadata,
6-
serde::StringEnum,
6+
serde::{PartialEqAsRefStr, StringEnum},
77
};
88

99
const METADATA: Metadata = metadata! {
@@ -39,8 +39,9 @@ impl Response {
3939
}
4040
}
4141

42-
#[derive(Clone, PartialEq, StringEnum)]
42+
#[derive(Clone, PartialEqAsRefStr, Eq, StringEnum)]
4343
#[ruma_enum(rename_all = "snake_case")]
44+
#[non_exhaustive]
4445
pub enum JobName {
4546
/// Recalculate the stats for all rooms.
4647
PopulateStatsProcessRooms,

src/rooms/list_rooms/v1.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use ruma::{
33
api::{metadata, request, response, Metadata},
44
events::room::{guest_access::GuestAccess, history_visibility::HistoryVisibility},
55
room::RoomType,
6-
serde::StringEnum,
6+
serde::{OrdAsRefStr, PartialEqAsRefStr, PartialOrdAsRefStr, StringEnum},
77
space::SpaceRoomJoinRule,
88
OwnedRoomAliasId, OwnedRoomId, OwnedUserId, UInt,
99
};
@@ -82,8 +82,9 @@ impl Response {
8282
}
8383

8484
/// Enum to define the sorting method of rooms.
85-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, StringEnum)]
85+
#[derive(Clone, PartialEqAsRefStr, Eq, PartialOrdAsRefStr, OrdAsRefStr, StringEnum)]
8686
#[ruma_enum(rename_all = "snake_case")]
87+
#[non_exhaustive]
8788
pub enum RoomSortOrder {
8889
/// Sort by name alphabetical
8990
Name,
@@ -129,7 +130,8 @@ pub enum RoomSortOrder {
129130
}
130131

131132
/// Enum to define the sort order direction.
132-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, StringEnum)]
133+
#[derive(Clone, PartialEqAsRefStr, Eq, PartialOrdAsRefStr, OrdAsRefStr, StringEnum)]
134+
#[non_exhaustive]
133135
pub enum SortDirection {
134136
/// Sort direction backward.
135137
#[ruma_enum(rename = "b")]

0 commit comments

Comments
 (0)