Skip to content

Commit

Permalink
Adds "unstable-exhaustive-types" as new feature.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TheCataliasTNT2k committed Nov 25, 2024
1 parent 4b9756c commit d855f04
Show file tree
Hide file tree
Showing 73 changed files with 328 additions and 320 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ native_tls_backend = [
"bytes",
]

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



[package.metadata.docs.rs]
features = ["full"]
Expand Down
2 changes: 1 addition & 1 deletion src/builder/create_attachment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::model::id::AttachmentId;
///
/// [Discord docs](https://discord.com/developers/docs/resources/channel#attachment-object-attachment-structure).
#[derive(Clone, Debug, Serialize, PartialEq)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
#[must_use]
pub struct CreateAttachment {
pub(crate) id: u64, // Placeholder ID will be filled in when sending the request
Expand Down
2 changes: 1 addition & 1 deletion src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub(crate) struct CachedShardData {
/// [`http`]: crate::http
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Debug)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub struct Cache {
// Temp cache:
// ---
Expand Down
2 changes: 1 addition & 1 deletion src/cache/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::time::Duration;
/// ```
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub struct Settings {
/// The maximum number of messages to store in a channel's message cache.
///
Expand Down
2 changes: 1 addition & 1 deletion src/client/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::fmt;
/// [`Client`]: super::Client
/// [`Error::Client`]: crate::Error::Client
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum Error {
/// When a shard has completely failed to reboot after resume and/or reconnect attempts.
ShardBootFailure,
Expand Down
2 changes: 1 addition & 1 deletion src/client/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ macro_rules! event_handler {
}

/// This enum stores every possible event that an [`EventHandler`] can receive.
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
#[allow(clippy::large_enum_variant)] // TODO: do some boxing to fix this
#[derive(Clone, Debug)]
pub enum FullEvent {
Expand Down
2 changes: 1 addition & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ enum_number! {
/// [Discord docs](https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway-gateway-opcodes).
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
#[serde(from = "u8", into = "u8")]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum Opcode {
/// Dispatches an event.
Dispatch = 0,
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub type Result<T, E = Error> = StdResult<T, E>;
/// The most common error types, the [`ClientError`] and [`GatewayError`] enums, are both wrapped
/// around this in the form of the [`Self::Client`] and [`Self::Gateway`] variants.
#[derive(Debug)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum Error {
/// An error while decoding a payload.
Decode(&'static str, Value),
Expand Down
2 changes: 1 addition & 1 deletion src/framework/standard/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use uwl::Stream;

/// Defines how an operation on an [`Args`] method failed.
#[derive(Debug)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum Error<E> {
/// "END-OF-STRING". We reached the end. There's nothing to parse anymore.
Eos,
Expand Down
4 changes: 2 additions & 2 deletions src/framework/standard/help_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub struct SuggestedCommandName {

/// A single command containing all related pieces of information.
#[derive(Clone, Debug)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub struct Command<'a> {
pub name: &'static str,
pub group_name: &'static str,
Expand Down Expand Up @@ -172,7 +172,7 @@ impl Suggestions {
/// Covers possible outcomes of a help-request and yields relevant data in customised textual
/// representation.
#[derive(Clone, Debug)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum CustomisedHelpData<'a> {
/// To display suggested commands.
SuggestedCommands { help_description: String, suggestions: Suggestions },
Expand Down
2 changes: 1 addition & 1 deletion src/framework/standard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use crate::model::{guild::Role, id::RoleId};

/// An enum representing all possible fail conditions under which a command won't be executed.
#[derive(Debug)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum DispatchError {
/// When a custom function check has failed.
CheckFailed(&'static str, Reason),
Expand Down
2 changes: 1 addition & 1 deletion src/framework/standard/structures/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::model::channel::Message;
/// solely serves as a way to inform a user about why a check has failed and for the developer to
/// log given failure (e.g. bugs or statistics) occurring in [`Check`]s.
#[derive(Clone, Debug)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum Reason {
/// No information on the failure.
Unknown,
Expand Down
4 changes: 2 additions & 2 deletions src/framework/standard/structures/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod check;
pub use self::check::*;

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum OnlyIn {
Dm,
Guild,
Expand Down Expand Up @@ -129,7 +129,7 @@ impl PartialEq for HelpCommand {
/// - Lacking required roles to execute the command.
/// - The command can't be used in the current channel (as in `DM only` or `guild only`).
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum HelpBehaviour {
/// The command will be displayed, hence nothing will be done.
Nothing,
Expand Down
2 changes: 1 addition & 1 deletion src/gateway/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tokio_tungstenite::tungstenite::protocol::CloseFrame;
/// Note that - from a user standpoint - there should be no situation in which you manually handle
/// these.
#[derive(Clone, Debug)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum Error {
/// There was an error building a URL.
BuildingUrl,
Expand Down
6 changes: 3 additions & 3 deletions src/gateway/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl From<Activity> for ActivityData {
///
/// This can be useful for knowing which shards are currently "down"/"up".
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum ConnectionStage {
/// Indicator that the [`Shard`] is normally connected and is not in, e.g., a resume phase.
Connected,
Expand Down Expand Up @@ -237,7 +237,7 @@ impl fmt::Display for ConnectionStage {
}

#[derive(Debug)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum ShardAction {
Heartbeat,
Identify,
Expand All @@ -246,7 +246,7 @@ pub enum ShardAction {

/// The type of reconnection that should be performed.
#[derive(Debug)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum ReconnectType {
/// Indicator that a new connection should be made by sending an IDENTIFY.
Reidentify,
Expand Down
6 changes: 3 additions & 3 deletions src/http/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::internal::prelude::*;
use crate::json::*;

#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub struct DiscordJsonError {
/// The error code.
pub code: isize,
Expand All @@ -32,7 +32,7 @@ pub struct DiscordJsonSingleError {
}

#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub struct ErrorResponse {
pub status_code: StatusCode,
pub url: String,
Expand All @@ -57,7 +57,7 @@ impl ErrorResponse {
}

#[derive(Debug)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum HttpError {
/// When a non-successful status code was received for a request.
UnsuccessfulRequest(ErrorResponse),
Expand Down
6 changes: 3 additions & 3 deletions src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl LightMethod {
}

/// Representation of the method of a query to send for the [`Http::get_guilds`] function.
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum GuildPagination {
/// The Id to get the guilds after.
After(GuildId),
Expand All @@ -176,7 +176,7 @@ pub enum GuildPagination {

/// Representation of the method of a query to send for the [`Http::get_scheduled_event_users`] and
/// [`Http::get_bans`] functions.
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum UserPagination {
/// The Id to get the users after.
After(UserId),
Expand All @@ -185,7 +185,7 @@ pub enum UserPagination {
}

#[derive(Clone, Copy, Debug)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum MessagePagination {
After(MessageId),
Around(MessageId),
Expand Down
2 changes: 1 addition & 1 deletion src/http/ratelimiting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use crate::internal::prelude::*;
/// Passed to the [`Ratelimiter::set_ratelimit_callback`] callback. If using Client, that callback
/// is initialized to call the `EventHandler::ratelimit()` method.
#[derive(Clone, Debug)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub struct RatelimitInfo {
pub timeout: std::time::Duration,
pub limit: i64,
Expand Down
18 changes: 9 additions & 9 deletions src/model/application/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::model::Permissions;
/// [Discord docs](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-structure).
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub struct Command {
/// The command Id.
pub id: CommandId,
Expand Down Expand Up @@ -241,7 +241,7 @@ enum_number! {
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[serde(from = "u8", into = "u8")]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum CommandType {
ChatInput = 1,
User = 2,
Expand All @@ -259,7 +259,7 @@ enum_number! {
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[serde(from = "u8", into = "u8")]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum EntryPointHandlerType {
AppHandler = 1,
DiscordLaunchActivity = 2,
Expand All @@ -272,7 +272,7 @@ enum_number! {
/// [Discord docs](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-structure).
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub struct CommandOption {
/// The option type.
#[serde(rename = "type")]
Expand Down Expand Up @@ -334,7 +334,7 @@ enum_number! {
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[serde(from = "u8", into = "u8")]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum CommandOptionType {
SubCommand = 1,
SubCommandGroup = 2,
Expand All @@ -356,7 +356,7 @@ enum_number! {
/// [Discord docs](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-choice-structure).
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub struct CommandOptionChoice {
/// The choice name.
pub name: String,
Expand All @@ -372,7 +372,7 @@ pub struct CommandOptionChoice {
/// [Discord docs](https://discord.com/developers/docs/interactions/application-commands#application-command-permissions-object-guild-application-command-permissions-structure).
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub struct CommandPermissions {
/// The id of the command.
pub id: CommandId,
Expand All @@ -389,7 +389,7 @@ pub struct CommandPermissions {
/// [Discord docs](https://discord.com/developers/docs/interactions/application-commands#application-command-permissions-object-application-command-permissions-structure).
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub struct CommandPermission {
/// The [`RoleId`] or [`UserId`], depends on `kind` value.
pub id: CommandPermissionId,
Expand All @@ -407,7 +407,7 @@ enum_number! {
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[serde(from = "u8", into = "u8")]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum CommandPermissionType {
Role = 1,
User = 2,
Expand Down
Loading

0 comments on commit d855f04

Please sign in to comment.