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 24, 2024
1 parent 5e275eb commit 547837f
Show file tree
Hide file tree
Showing 68 changed files with 322 additions and 315 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ native_tls_backend = [
"tokio-tungstenite/native-tls",
]

# 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 @@ -18,7 +18,7 @@ use crate::model::id::AttachmentId;
///
/// [Discord docs](https://discord.com/developers/docs/resources/channel#attachment-object-attachment-structure).
#[derive(Clone, Debug)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
#[must_use]
pub struct CreateAttachment<'a> {
pub filename: Cow<'static, str>,
Expand Down
2 changes: 1 addition & 1 deletion src/builder/create_interaction_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl<'a> CreateInteractionResponseMessage<'a> {

#[derive(Clone, Debug, Serialize)]
#[serde(untagged)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
#[must_use]
pub enum AutocompleteValue<'a> {
String(Cow<'a, str>),
Expand Down
2 changes: 1 addition & 1 deletion src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,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 @@ -12,7 +12,7 @@
/// ```
#[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 {
/// How long temporarily-cached data should be stored before being thrown out.
///
Expand Down
2 changes: 1 addition & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,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)]
#[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 @@ -24,7 +24,7 @@ pub type Result<T, E = Error> = StdResult<T, E>;

/// A common error enum returned by most of the library's functionality within a custom [`Result`].
#[derive(Debug)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum Error {
/// An [`std::io`] error.
Io(IoError),
Expand Down
2 changes: 1 addition & 1 deletion src/gateway/client/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ macro_rules! event_handler {
}

/// This enum stores every possible event that an [`EventHandler`] can receive.
#[cfg_attr(not(feature = "unstable"), non_exhaustive)]
#[cfg_attr(any(not(any(feature = "unstable_exhaustive_types"), feature = "unstable"), doc), non_exhaustive)]
#[derive(Clone, Debug, VariantNames, IntoStaticStr, EnumCount, Serialize)]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
pub enum FullEvent {
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(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
8 changes: 4 additions & 4 deletions src/gateway/sharding/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ fn deserialize_and_log_event(map: JsonMap, original_str: &str) -> Result<Event>
}

#[derive(Debug)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum ShardAction {
Heartbeat,
Identify,
Expand Down Expand Up @@ -895,7 +895,7 @@ pub struct ShardStageUpdateEvent {
///
/// This can be useful for knowing which shards are currently "down"/"up".
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
#[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 @@ -961,7 +961,7 @@ impl fmt::Display for ConnectionStage {

/// 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 Expand Up @@ -992,7 +992,7 @@ impl PartialEq for CollectorCallback {

/// The transport compression method to use.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum TransportCompression {
/// No transport compression. Payload compression will be used instead.
None,
Expand Down
8 changes: 4 additions & 4 deletions src/http/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::internal::prelude::*;

enum_number! {
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum JsonErrorCode {
General = 0,

Expand Down Expand Up @@ -246,7 +246,7 @@ enum_number! {
}

#[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: JsonErrorCode,
Expand Down Expand Up @@ -275,7 +275,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 method: Method,
pub status_code: StatusCode,
Expand All @@ -300,7 +300,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 @@ -132,7 +132,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 @@ -142,7 +142,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 @@ -151,7 +151,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 @@ -54,7 +54,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, Serialize)]
#[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 @@ -15,7 +15,7 @@ use crate::model::prelude::*;
#[bool_to_bitflags::bool_to_bitflags]
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, serde::Deserialize, serde::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 @@ -216,7 +216,7 @@ enum_number! {
/// [Discord docs](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-types).
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum CommandType {
ChatInput = 1,
User = 2,
Expand All @@ -233,7 +233,7 @@ enum_number! {
/// [Discord docs](https://discord.com/developers/docs/interactions/application-commands#application-command-object-entry-point-command-handler-types)
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum EntryPointHandlerType {
AppHandler = 1,
DiscordLaunchActivity = 2,
Expand All @@ -246,7 +246,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, serde::Deserialize, serde::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 @@ -307,7 +307,7 @@ enum_number! {
/// [Discord docs](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-type).
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum CommandOptionType {
SubCommand = 1,
SubCommandGroup = 2,
Expand All @@ -329,7 +329,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: FixedString,
Expand All @@ -345,7 +345,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 @@ -362,7 +362,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 @@ -379,7 +379,7 @@ enum_number! {
/// [Discord docs](https://discord.com/developers/docs/interactions/application-commands#application-command-permissions-object-application-command-permission-type).
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum CommandPermissionType {
Role = 1,
User = 2,
Expand Down
20 changes: 10 additions & 10 deletions src/model/application/command_interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::utils::{CreateQuickModal, QuickModalResponse};
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(remote = "Self")]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub struct CommandInteraction {
/// Id of the interaction.
pub id: InteractionId,
Expand Down Expand Up @@ -251,7 +251,7 @@ impl Serialize for CommandInteraction {
/// [Discord docs](https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-data-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 CommandData {
/// The Id of the invoked command.
pub id: CommandId,
Expand Down Expand Up @@ -404,23 +404,23 @@ impl CommandData {

/// The focused option for autocomplete interactions return by [`CommandData::autocomplete`].
#[derive(Clone, Debug)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub struct AutocompleteOption<'a> {
pub name: &'a str,
pub kind: CommandOptionType,
pub value: &'a str,
}

#[derive(Clone, Debug)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub struct ResolvedOption<'a> {
pub name: &'a str,
pub value: ResolvedValue<'a>,
}

/// The resolved value of a [`CommandDataOption`].
#[derive(Clone, Debug)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum ResolvedValue<'a> {
Autocomplete { kind: CommandOptionType, value: &'a str },
Boolean(bool),
Expand All @@ -438,7 +438,7 @@ pub enum ResolvedValue<'a> {

/// Option value variants that couldn't be resolved by `CommandData::options()`.
#[derive(Clone, Debug)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum Unresolved {
Attachment(AttachmentId),
Channel(ChannelId),
Expand All @@ -451,7 +451,7 @@ pub enum Unresolved {

/// The resolved value of a [`CommandData::target_id`].
#[derive(Clone, Debug)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum ResolvedTarget<'a> {
User(&'a User, Option<&'a PartialMember>),
Message(&'a Message),
Expand All @@ -463,7 +463,7 @@ pub enum ResolvedTarget<'a> {
/// [Discord docs](https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-resolved-data-structure).
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub struct CommandDataResolved {
/// The resolved users.
#[serde(
Expand Down Expand Up @@ -517,7 +517,7 @@ pub struct CommandDataResolved {
/// [Discord docs](https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-application-command-interaction-data-option-structure).
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub struct CommandDataOption {
/// The name of the parameter.
pub name: FixedString,
Expand Down Expand Up @@ -640,7 +640,7 @@ impl Serialize for CommandDataOption {
/// [Discord docs](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-type).
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
pub enum CommandDataOptionValue {
Autocomplete { kind: CommandOptionType, value: FixedString },
Boolean(bool),
Expand Down
Loading

0 comments on commit 547837f

Please sign in to comment.