Repository: krojew/cdrs-tokio (language: rust)

Issue:
Add non exhaustive to proto enums
We should add non exhaustive to enums which are likely to change upstream. 


Discussion / hints:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.


Fix patch:
diff --git a/cassandra-protocol/src/consistency.rs b/cassandra-protocol/src/consistency.rs
index 939c9f5..ea84d05 100644
--- a/cassandra-protocol/src/consistency.rs
+++ b/cassandra-protocol/src/consistency.rs
@@ -13,6 +13,7 @@ use std::str::FromStr;
 /// To find more details about each consistency level please refer to the following documentation:
 /// <https://docs.datastax.com/en/cql-oss/3.x/cql/cql_reference/cqlshConsistency.html>
 #[derive(Debug, PartialEq, Clone, Copy, Display, Ord, PartialOrd, Eq, Hash)]
+#[non_exhaustive]
 pub enum Consistency {
     /// Closest replica, as determined by the snitch.
     /// If all replica nodes are down, write succeeds after a hinted handoff.
diff --git a/cassandra-protocol/src/error.rs b/cassandra-protocol/src/error.rs
index fa4cadc..bc0e98c 100644
--- a/cassandra-protocol/src/error.rs
+++ b/cassandra-protocol/src/error.rs
@@ -19,6 +19,7 @@ pub type Result<T> = result::Result<T, Error>;
 /// can be raised by CDRS driver. `Server` error is an error which are ones returned by
 /// a Server via result error frames.
 #[derive(Debug, ThisError)]
+#[non_exhaustive]
 pub enum Error {
     /// Internal IO error.
     #[error("IO error: {0}")]
diff --git a/cassandra-protocol/src/frame.rs b/cassandra-protocol/src/frame.rs
index 3d44e14..6305f50 100644
--- a/cassandra-protocol/src/frame.rs
+++ b/cassandra-protocol/src/frame.rs
@@ -314,6 +314,7 @@ impl Envelope {
 }
 
 #[derive(Debug, Error)]
+#[non_exhaustive]
 pub enum CheckEnvelopeSizeError {
     #[error("Not enough bytes!")]
     NotEnoughBytes,
@@ -324,6 +325,7 @@ pub enum CheckEnvelopeSizeError {
 }
 
 #[derive(Debug, Error)]
+#[non_exhaustive]
 pub enum ParseEnvelopeError {
     /// There are not enough bytes to parse a single envelope, [`Envelope::from_buffer`] should be recalled when it is possible that there are more bytes.
     #[error("Not enough bytes!")]
@@ -343,6 +345,7 @@ pub enum ParseEnvelopeError {
 
 /// Protocol version.
 #[derive(Debug, PartialEq, Copy, Clone, Ord, PartialOrd, Eq, Hash, Display)]
+#[non_exhaustive]
 pub enum Version {
     V3,
     V4,
@@ -428,6 +431,7 @@ impl Flags {
 }
 
 #[derive(Debug, PartialEq, Copy, Clone, Ord, PartialOrd, Eq, Hash, Display)]
+#[non_exhaustive]
 pub enum Opcode {
     Error,
     Startup,
diff --git a/cassandra-protocol/src/frame/events.rs b/cassandra-protocol/src/frame/events.rs
index 11b760c..3a76c01 100644
--- a/cassandra-protocol/src/frame/events.rs
+++ b/cassandra-protocol/src/frame/events.rs
@@ -37,6 +37,7 @@ const AGGREGATE: &str = "AGGREGATE";
 /// about a concrete change. It may be useful for subscription
 /// when you need only string representation of an event.
 #[derive(Debug, PartialEq, Copy, Clone, Ord, PartialOrd, Eq, Hash)]
+#[non_exhaustive]
 pub enum SimpleServerEvent {
     TopologyChange,
     StatusChange,
@@ -94,6 +95,7 @@ impl PartialEq<ServerEvent> for SimpleServerEvent {
 
 /// Full server event that contains all details about a concrete change.
 #[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
+#[non_exhaustive]
 pub enum ServerEvent {
     /// Events related to change in the cluster topology
     TopologyChange(TopologyChange),
@@ -171,6 +173,7 @@ impl FromCursor for TopologyChange {
 }
 
 #[derive(Debug, Copy, Clone, PartialEq, Ord, PartialOrd, Eq, Hash, Display)]
+#[non_exhaustive]
 pub enum TopologyChangeType {
     NewNode,
     RemovedNode,
@@ -223,6 +226,7 @@ impl FromCursor for StatusChange {
 }
 
 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Display)]
+#[non_exhaustive]
 pub enum StatusChangeType {
     Up,
     Down,
@@ -282,6 +286,7 @@ impl FromCursor for SchemaChange {
 
 /// Represents type of changes.
 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Display)]
+#[non_exhaustive]
 pub enum SchemaChangeType {
     Created,
     Updated,
@@ -314,6 +319,7 @@ impl FromCursor for SchemaChangeType {
 
 /// Refers to a target of changes were made.
 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Display)]
+#[non_exhaustive]
 pub enum SchemaChangeTarget {
     Keyspace,
     Table,
@@ -352,6 +358,7 @@ impl FromCursor for SchemaChangeTarget {
 
 /// Information about changes made.
 #[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
+#[non_exhaustive]
 pub enum SchemaChangeOptions {
     /// Changes related to keyspaces. Contains keyspace name.
     Keyspace(String),
diff --git a/cassandra-protocol/src/frame/message_batch.rs b/cassandra-protocol/src/frame/message_batch.rs
index 7647309..6a05926 100644
--- a/cassandra-protocol/src/frame/message_batch.rs
+++ b/cassandra-protocol/src/frame/message_batch.rs
@@ -130,6 +130,7 @@ impl FromCursor for BodyReqBatch {
 
 /// Batch type
 #[derive(Debug, Clone, Copy, PartialEq, Ord, PartialOrd, Eq, Hash, Display)]
+#[non_exhaustive]
 pub enum BatchType {
     /// The batch will be "logged". This is equivalent to a
     /// normal CQL3 batch statement.
diff --git a/cassandra-protocol/src/frame/message_error.rs b/cassandra-protocol/src/frame/message_error.rs
index 3f8f419..6e2ca27 100644
--- a/cassandra-protocol/src/frame/message_error.rs
+++ b/cassandra-protocol/src/frame/message_error.rs
@@ -43,6 +43,7 @@ impl FromCursor for ErrorBody {
 /// Protocol-dependent failure information. V5 contains a map of endpoint->code entries, while
 /// previous versions contain only error count.
 #[derive(Debug, PartialEq, Eq, Clone)]
+#[non_exhaustive]
 pub enum FailureInfo {
     /// Represents the number of nodes that experience a failure while executing the request.
     NumFailures(CInt),
diff --git a/cassandra-protocol/src/frame/message_request.rs b/cassandra-protocol/src/frame/message_request.rs
index dc539a3..b142c73 100644
--- a/cassandra-protocol/src/frame/message_request.rs
+++ b/cassandra-protocol/src/frame/message_request.rs
@@ -13,6 +13,7 @@ use crate::{error, Error};
 
 #[derive(Debug, PartialEq, Eq, Clone)]
 #[allow(clippy::large_enum_variant)]
+#[non_exhaustive]
 pub enum RequestBody {
     Startup(BodyReqStartup),
     Options(BodyReqOptions),
diff --git a/cassandra-protocol/src/frame/message_response.rs b/cassandra-protocol/src/frame/message_response.rs
index a36190b..cd24e14 100644
--- a/cassandra-protocol/src/frame/message_response.rs
+++ b/cassandra-protocol/src/frame/message_response.rs
@@ -14,6 +14,7 @@ use crate::types::rows::Row;
 use crate::{error, Error};
 
 #[derive(Debug, PartialEq, Eq, Clone)]
+#[non_exhaustive]
 pub enum ResponseBody {
     Error(ErrorBody),
     Ready,
diff --git a/cassandra-protocol/src/frame/message_result.rs b/cassandra-protocol/src/frame/message_result.rs
index f0356de..8a4d992 100644
--- a/cassandra-protocol/src/frame/message_result.rs
+++ b/cassandra-protocol/src/frame/message_result.rs
@@ -14,6 +14,7 @@ use std::io::{Cursor, Error as IoError, Read};
 
 /// `ResultKind` is enum which represents types of result.
 #[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Copy, Clone, Hash, Display)]
+#[non_exhaustive]
 pub enum ResultKind {
     /// Void result.
     Void,
@@ -82,6 +83,7 @@ impl FromCursor for ResultKind {
 /// `ResponseBody` is a generalized enum that represents all types of responses. Each of enum
 /// option wraps related body type.
 #[derive(Debug, PartialEq, Ord, PartialOrd, Eq, Clone, Hash)]
+#[non_exhaustive]
 pub enum ResResultBody {
     /// Void response body. It's an empty struct.
     Void,
@@ -502,6 +504,7 @@ impl ColSpec {
 
 /// Cassandra data types which could be returned by a server.
 #[derive(Debug, Clone, Display, Copy, Ord, PartialOrd, Eq, PartialEq, Hash)]
+#[non_exhaustive]
 pub enum ColType {
     Custom,
     Ascii,
@@ -678,6 +681,7 @@ impl FromCursor for ColTypeOption {
 
 /// Enum that represents all possible types of `value` of `ColTypeOption`.
 #[derive(Debug, Clone, PartialEq, Ord, PartialOrd, Eq, Hash)]
+#[non_exhaustive]
 pub enum ColTypeOptionValue {
     CString(String),
     ColType(ColType),
diff --git a/cassandra-protocol/src/types/cassandra_type.rs b/cassandra-protocol/src/types/cassandra_type.rs
index f7a7a5c..b939699 100644
--- a/cassandra-protocol/src/types/cassandra_type.rs
+++ b/cassandra-protocol/src/types/cassandra_type.rs
@@ -9,6 +9,7 @@ use crate::frame::Version;
 use crate::types::CBytes;
 
 #[derive(Debug, PartialEq, Clone)]
+#[non_exhaustive]
 pub enum CassandraType {
     Ascii(String),
     Bigint(i64),
diff --git a/cdrs-tokio-helpers-derive/src/common.rs b/cdrs-tokio-helpers-derive/src/common.rs
index b3071e8..3e810a7 100644
--- a/cdrs-tokio-helpers-derive/src/common.rs
+++ b/cdrs-tokio-helpers-derive/src/common.rs
@@ -191,7 +191,7 @@ fn get_ident(ty: &Type) -> &Ident {
             path: Path { segments, .. },
             ..
         }) => match segments.last() {
-            Some(&PathSegment { ref ident, .. }) => ident,
+            Some(PathSegment { ident, .. }) => ident,
             _ => panic!("Cannot infer field type"),
         },
         _ => panic!("Cannot infer field type {}", get_ident_string(ty)),
diff --git a/cdrs-tokio/src/cluster/cluster_metadata_manager.rs b/cdrs-tokio/src/cluster/cluster_metadata_manager.rs
index 07ba9f1..b0d02d6 100644
--- a/cdrs-tokio/src/cluster/cluster_metadata_manager.rs
+++ b/cdrs-tokio/src/cluster/cluster_metadata_manager.rs
@@ -371,6 +371,7 @@ impl<T: CdrsTransport + 'static, CM: ConnectionManager<T> + 'static> ClusterMeta
             ServerEvent::TopologyChange(event) => self.process_topology_event(event).await,
             ServerEvent::StatusChange(event) => self.process_status_event(event).await,
             ServerEvent::SchemaChange(event) => self.process_schema_event(event).await,
+            _ => warn!(?event, "Unrecognized event."),
         }
     }
 
@@ -383,6 +384,7 @@ impl<T: CdrsTransport + 'static, CM: ConnectionManager<T> + 'static> ClusterMeta
                 SchemaChangeType::Dropped => {
                     self.remove_keyspace(keyspace);
                 }
+                _ => warn!(?event, "Unrecognized schema event."),
             }
         }
     }
@@ -414,6 +416,7 @@ impl<T: CdrsTransport + 'static, CM: ConnectionManager<T> + 'static> ClusterMeta
                     );
                 }
             }
+            _ => warn!(?event, "Unrecognized topology change type."),
         }
     }
 
@@ -453,6 +456,7 @@ impl<T: CdrsTransport + 'static, CM: ConnectionManager<T> + 'static> ClusterMeta
                     debug!(broadcast_rpc_address = %event.addr, "Unknown node down.");
                 }
             }
+            _ => warn!(?event, "Unrecognized status event."),
         }
     }
 


Test patch: