Skip to content

Commit 61c21d9

Browse files
committed
scylla_cql: autoderive Default for Consistency
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.
1 parent 1c9d0e3 commit 61c21d9

File tree

3 files changed

+4
-19
lines changed

3 files changed

+4
-19
lines changed

scylla-cql/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ license = "MIT OR Apache-2.0"
1313
scylla-macros = { version = "0.2.0", path = "../scylla-macros"}
1414
byteorder = "1.3.4"
1515
bytes = "1.0.1"
16-
num_enum = "0.5"
16+
num_enum = "0.6"
1717
tokio = { version = "1.12", features = ["io-util", "time"] }
1818
secrecy = { version = "0.7.0", optional = true }
1919
snap = "1.0"

scylla-cql/src/frame/types.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::net::SocketAddr;
1212
use std::str;
1313
use uuid::Uuid;
1414

15-
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, TryFromPrimitive)]
15+
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, TryFromPrimitive)]
1616
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
1717
#[cfg_attr(feature = "serde", serde(rename_all = "SCREAMING_SNAKE_CASE"))]
1818
#[repr(i16)]
@@ -23,6 +23,7 @@ pub enum Consistency {
2323
Three = 0x0003,
2424
Quorum = 0x0004,
2525
All = 0x0005,
26+
#[default]
2627
LocalQuorum = 0x0006,
2728
EachQuorum = 0x0007,
2829
LocalOne = 0x000A,
@@ -46,22 +47,6 @@ pub enum LegacyConsistency {
4647
Serial(SerialConsistency),
4748
}
4849

49-
// Although we could `impl Default for Consistency` with an automatic derive,
50-
// this would require adding a #[default] annotation on the default variant,
51-
// but - unfortunately - that annotation is also recognized by `TryFromPrimitive`
52-
// derive macro. If there is a #[default] variant then `TryFromPrimitive`
53-
// falls back to it - if not, then it returns an error. This breaks one of the
54-
// tests.
55-
//
56-
// It will be possible to fix this properly after the following issue is closed:
57-
// https://github.com/illicitonion/num_enum/issues/75
58-
#[allow(clippy::derivable_impls)]
59-
impl Default for Consistency {
60-
fn default() -> Self {
61-
Consistency::LocalQuorum
62-
}
63-
}
64-
6550
impl std::fmt::Display for Consistency {
6651
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
6752
write!(f, "{:?}", self)

scylla/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ byteorder = "1.3.4"
2626
bytes = "1.0.1"
2727
futures = "0.3.6"
2828
histogram = "0.6.9"
29-
num_enum = "0.5"
29+
num_enum = "0.6"
3030
tokio = { version = "1.27", features = ["net", "time", "io-util", "sync", "rt", "macros"] }
3131
snap = "1.0"
3232
uuid = { version = "1.0", features = ["v4"] }

0 commit comments

Comments
 (0)