Skip to content

Commit 620ecb7

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 2a10492 commit 620ecb7

Some content is hidden

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

74 files changed

+329
-331
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ native_tls_backend = [
153153
"bytes",
154154
]
155155

156+
# Disables all "#[non_exhaustive]" macros, to ensure that all enum variants or struct fields are required when pattern matching.
157+
unstable_exhaustive_types = ["serenity-voice-model/unstable_exhaustive_types"]
158+
159+
156160

157161
[package.metadata.docs.rs]
158162
features = ["full"]

src/builder/create_attachment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::model::id::AttachmentId;
1717
///
1818
/// [Discord docs](https://discord.com/developers/docs/resources/channel#attachment-object-attachment-structure).
1919
#[derive(Clone, Debug, Serialize, PartialEq)]
20-
#[non_exhaustive]
20+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
2121
#[must_use]
2222
pub struct CreateAttachment {
2323
pub(crate) id: u64, // Placeholder ID will be filled in when sending the request

src/cache/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub(crate) struct CachedShardData {
152152
/// [`http`]: crate::http
153153
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
154154
#[derive(Debug)]
155-
#[non_exhaustive]
155+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
156156
pub struct Cache {
157157
// Temp cache:
158158
// ---

src/cache/settings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::time::Duration;
1414
/// ```
1515
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
1616
#[derive(Clone, Debug)]
17-
#[non_exhaustive]
17+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
1818
pub struct Settings {
1919
/// The maximum number of messages to store in a channel's message cache.
2020
///

src/client/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::fmt;
88
/// [`Client`]: super::Client
99
/// [`Error::Client`]: crate::Error::Client
1010
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
11-
#[non_exhaustive]
11+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
1212
pub enum Error {
1313
/// When a shard has completely failed to reboot after resume and/or reconnect attempts.
1414
ShardBootFailure,

src/client/event_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ macro_rules! event_handler {
2727
}
2828

2929
/// This enum stores every possible event that an [`EventHandler`] can receive.
30-
#[non_exhaustive]
30+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
3131
#[allow(clippy::large_enum_variant)] // TODO: do some boxing to fix this
3232
#[derive(Clone, Debug)]
3333
pub enum FullEvent {

src/constants.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ enum_number! {
3535
///
3636
/// [Discord docs](https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway-gateway-opcodes).
3737
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
38-
#[serde(from = "u8", into = "u8")]
39-
#[non_exhaustive]
38+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
4039
pub enum Opcode {
4140
/// Dispatches an event.
4241
Dispatch = 0,

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub type Result<T, E = Error> = StdResult<T, E>;
3030
/// The most common error types, the [`ClientError`] and [`GatewayError`] enums, are both wrapped
3131
/// around this in the form of the [`Self::Client`] and [`Self::Gateway`] variants.
3232
#[derive(Debug)]
33-
#[non_exhaustive]
33+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
3434
pub enum Error {
3535
/// An error while decoding a payload.
3636
Decode(&'static str, Value),

src/framework/standard/args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use uwl::Stream;
88

99
/// Defines how an operation on an [`Args`] method failed.
1010
#[derive(Debug)]
11-
#[non_exhaustive]
11+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
1212
pub enum Error<E> {
1313
/// "END-OF-STRING". We reached the end. There's nothing to parse anymore.
1414
Eos,

src/framework/standard/help_commands.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub struct SuggestedCommandName {
120120

121121
/// A single command containing all related pieces of information.
122122
#[derive(Clone, Debug)]
123-
#[non_exhaustive]
123+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
124124
pub struct Command<'a> {
125125
pub name: &'static str,
126126
pub group_name: &'static str,
@@ -172,7 +172,7 @@ impl Suggestions {
172172
/// Covers possible outcomes of a help-request and yields relevant data in customised textual
173173
/// representation.
174174
#[derive(Clone, Debug)]
175-
#[non_exhaustive]
175+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
176176
pub enum CustomisedHelpData<'a> {
177177
/// To display suggested commands.
178178
SuggestedCommands { help_description: String, suggestions: Suggestions },

0 commit comments

Comments
 (0)