Skip to content

Commit c1df749

Browse files
Adds "unstable-exhaustive-types" as new feature.
This feature deactivates all "#[non_exhaustive]" added into the code. This can be used by developers to ensure, that they match all enum variants or struct fields during pattern matching.
1 parent 7da8e2a commit c1df749

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+324
-316
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ native_tls_backend = [
149149
"tokio-tungstenite/native-tls",
150150
]
151151

152+
# Disables all "#[non_exhaustive]" macros to ensure, that all enum variants or struct fields are required when pattern matching.
153+
unstable_exhaustive_types = ["serenity-voice-model/unstable_exhaustive_types"]
154+
155+
152156

153157
[package.metadata.docs.rs]
154158
features = ["full"]

src/builder/create_attachment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::model::id::AttachmentId;
1818
///
1919
/// [Discord docs](https://discord.com/developers/docs/resources/channel#attachment-object-attachment-structure).
2020
#[derive(Clone, Debug)]
21-
#[non_exhaustive]
21+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
2222
#[must_use]
2323
pub struct CreateAttachment<'a> {
2424
pub filename: Cow<'static, str>,

src/builder/create_interaction_response.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl<'a> CreateInteractionResponseMessage<'a> {
291291

292292
#[derive(Clone, Debug, Serialize)]
293293
#[serde(untagged)]
294-
#[non_exhaustive]
294+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
295295
#[must_use]
296296
pub enum AutocompleteValue<'a> {
297297
String(Cow<'a, str>),

src/cache/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pub(crate) struct CachedShardData {
145145
/// [`http`]: crate::http
146146
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
147147
#[derive(Debug)]
148-
#[non_exhaustive]
148+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
149149
pub struct Cache {
150150
// Temp cache:
151151
// ---

src/cache/settings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/// ```
1313
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
1414
#[derive(Clone, Debug)]
15-
#[non_exhaustive]
15+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
1616
pub struct Settings {
1717
/// How long temporarily-cached data should be stored before being thrown out.
1818
///

src/constants.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ enum_number! {
4040
///
4141
/// [Discord docs](https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway-gateway-opcodes).
4242
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
43-
#[non_exhaustive]
43+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
4444
pub enum Opcode {
4545
/// Dispatches an event.
4646
Dispatch = 0,
@@ -75,7 +75,7 @@ enum_number! {
7575
///
7676
/// [Discord docs](https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway-gateway-close-event-codes)
7777
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
78-
#[non_exhaustive]
78+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
7979
pub enum CloseCode {
8080
/// Unknown error; try reconnecting.
8181
UnknownError = 4000,

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub type Result<T, E = Error> = StdResult<T, E>;
2626

2727
/// A common error enum returned by most of the library's functionality within a custom [`Result`].
2828
#[derive(Debug)]
29-
#[non_exhaustive]
29+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
3030
pub enum Error {
3131
/// An [`std::io`] error.
3232
Io(IoError),

src/gateway/client/event_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ macro_rules! event_handler {
4949
}
5050

5151
/// This enum stores every possible event that an [`EventHandler`] can receive.
52-
#[cfg_attr(not(feature = "unstable"), non_exhaustive)]
52+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
5353
#[derive(Clone, Debug, VariantNames, IntoStaticStr, EnumCount, Serialize)]
5454
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
5555
pub enum FullEvent {

src/gateway/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use tokio_tungstenite::tungstenite::protocol::CloseFrame;
88
/// Note that - from a user standpoint - there should be no situation in which you manually handle
99
/// these.
1010
#[derive(Debug)]
11-
#[non_exhaustive]
11+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
1212
pub enum Error {
1313
/// There was an error building a URL.
1414
BuildingUrl,

src/gateway/sharding/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ struct ResumeMetadata {
763763
}
764764

765765
#[derive(Debug)]
766-
#[non_exhaustive]
766+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
767767
pub enum ShardAction {
768768
Heartbeat,
769769
Identify,
@@ -806,7 +806,7 @@ pub struct ShardStageUpdateEvent {
806806
///
807807
/// This can be useful for knowing which shards are currently "down"/"up".
808808
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
809-
#[non_exhaustive]
809+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
810810
pub enum ConnectionStage {
811811
/// Indicator that the [`Shard`] is normally connected and is not in, e.g., a resume phase.
812812
Connected,
@@ -893,7 +893,7 @@ impl PartialEq for CollectorCallback {
893893

894894
/// The transport compression method to use.
895895
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
896-
#[non_exhaustive]
896+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
897897
pub enum TransportCompression {
898898
/// No transport compression. Payload compression will be used instead.
899899
None,

0 commit comments

Comments
 (0)