Skip to content

Commit c9293b3

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 5e275eb commit c9293b3

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

+322
-315
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ native_tls_backend = [
139139
"tokio-tungstenite/native-tls",
140140
]
141141

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

143146
[package.metadata.docs.rs]
144147
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
@@ -143,7 +143,7 @@ pub(crate) struct CachedShardData {
143143
/// [`http`]: crate::http
144144
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
145145
#[derive(Debug)]
146-
#[non_exhaustive]
146+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
147147
pub struct Cache {
148148
// Temp cache:
149149
// ---

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: 1 addition & 1 deletion
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,

src/error.rs

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

2525
/// A common error enum returned by most of the library's functionality within a custom [`Result`].
2626
#[derive(Debug)]
27-
#[non_exhaustive]
27+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
2828
pub enum Error {
2929
/// An [`std::io`] error.
3030
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(any(feature = "unstable_exhaustive_types", feature = "unstable")), 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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ fn deserialize_and_log_event(map: JsonMap, original_str: &str) -> Result<Event>
853853
}
854854

855855
#[derive(Debug)]
856-
#[non_exhaustive]
856+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
857857
pub enum ShardAction {
858858
Heartbeat,
859859
Identify,
@@ -895,7 +895,7 @@ pub struct ShardStageUpdateEvent {
895895
///
896896
/// This can be useful for knowing which shards are currently "down"/"up".
897897
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
898-
#[non_exhaustive]
898+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
899899
pub enum ConnectionStage {
900900
/// Indicator that the [`Shard`] is normally connected and is not in, e.g., a resume phase.
901901
Connected,
@@ -961,7 +961,7 @@ impl fmt::Display for ConnectionStage {
961961

962962
/// The type of reconnection that should be performed.
963963
#[derive(Debug)]
964-
#[non_exhaustive]
964+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
965965
pub enum ReconnectType {
966966
/// Indicator that a new connection should be made by sending an IDENTIFY.
967967
Reidentify,
@@ -992,7 +992,7 @@ impl PartialEq for CollectorCallback {
992992

993993
/// The transport compression method to use.
994994
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
995-
#[non_exhaustive]
995+
#[cfg_attr(any(not(feature = "unstable_exhaustive_types"), doc), non_exhaustive)]
996996
pub enum TransportCompression {
997997
/// No transport compression. Payload compression will be used instead.
998998
None,

0 commit comments

Comments
 (0)