Skip to content

Commit

Permalink
scylla_cql: autoderive Default for Consistency
Browse files Browse the repository at this point in the history
As the awaited issue in `num_enum` crate
(illicitonion/num_enum#75) has been resolved
in its 0.6 release, it is now possible to derive Default for Consistency
automatically.
  • Loading branch information
wprzytula committed Jul 26, 2023
1 parent 1c9d0e3 commit 61c21d9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 19 deletions.
2 changes: 1 addition & 1 deletion scylla-cql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ license = "MIT OR Apache-2.0"
scylla-macros = { version = "0.2.0", path = "../scylla-macros"}
byteorder = "1.3.4"
bytes = "1.0.1"
num_enum = "0.5"
num_enum = "0.6"
tokio = { version = "1.12", features = ["io-util", "time"] }
secrecy = { version = "0.7.0", optional = true }
snap = "1.0"
Expand Down
19 changes: 2 additions & 17 deletions scylla-cql/src/frame/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::net::SocketAddr;
use std::str;
use uuid::Uuid;

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, TryFromPrimitive)]
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, TryFromPrimitive)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "SCREAMING_SNAKE_CASE"))]
#[repr(i16)]
Expand All @@ -23,6 +23,7 @@ pub enum Consistency {
Three = 0x0003,
Quorum = 0x0004,
All = 0x0005,
#[default]
LocalQuorum = 0x0006,
EachQuorum = 0x0007,
LocalOne = 0x000A,
Expand All @@ -46,22 +47,6 @@ pub enum LegacyConsistency {
Serial(SerialConsistency),
}

// Although we could `impl Default for Consistency` with an automatic derive,
// this would require adding a #[default] annotation on the default variant,
// but - unfortunately - that annotation is also recognized by `TryFromPrimitive`
// derive macro. If there is a #[default] variant then `TryFromPrimitive`
// falls back to it - if not, then it returns an error. This breaks one of the
// tests.
//
// It will be possible to fix this properly after the following issue is closed:
// https://github.com/illicitonion/num_enum/issues/75
#[allow(clippy::derivable_impls)]
impl Default for Consistency {
fn default() -> Self {
Consistency::LocalQuorum
}
}

impl std::fmt::Display for Consistency {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
Expand Down
2 changes: 1 addition & 1 deletion scylla/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ byteorder = "1.3.4"
bytes = "1.0.1"
futures = "0.3.6"
histogram = "0.6.9"
num_enum = "0.5"
num_enum = "0.6"
tokio = { version = "1.27", features = ["net", "time", "io-util", "sync", "rt", "macros"] }
snap = "1.0"
uuid = { version = "1.0", features = ["v4"] }
Expand Down

0 comments on commit 61c21d9

Please sign in to comment.