From 242bc2a5aa98351a225f48e224e85d26c8459539 Mon Sep 17 00:00:00 2001 From: muzarski Date: Thu, 15 Feb 2024 15:26:42 +0100 Subject: [PATCH 1/3] topology: remove usages of strum from `NativeType` Removed usages of `strum` crate from `NativeType` enum. Replaced it with our own parsing logic. --- scylla/src/transport/topology.rs | 37 ++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/scylla/src/transport/topology.rs b/scylla/src/transport/topology.rs index e7a2adcff2..0907a514e6 100644 --- a/scylla/src/transport/topology.rs +++ b/scylla/src/transport/topology.rs @@ -255,8 +255,7 @@ pub struct MissingUserDefinedType { pub keyspace: String, } -#[derive(Clone, Debug, PartialEq, Eq, EnumString)] -#[strum(serialize_all = "lowercase")] +#[derive(Clone, Debug, PartialEq, Eq)] pub enum NativeType { Ascii, Boolean, @@ -280,6 +279,40 @@ pub enum NativeType { Varint, } +/// [NativeType] parse error +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct NativeTypeFromStrError; + +impl std::str::FromStr for NativeType { + type Err = NativeTypeFromStrError; + + fn from_str(s: &str) -> Result { + match s { + "ascii" => Ok(Self::Ascii), + "boolean" => Ok(Self::Boolean), + "blob" => Ok(Self::Blob), + "counter" => Ok(Self::Counter), + "date" => Ok(Self::Date), + "decimal" => Ok(Self::Decimal), + "double" => Ok(Self::Double), + "duration" => Ok(Self::Duration), + "float" => Ok(Self::Float), + "int" => Ok(Self::Int), + "bigint" => Ok(Self::BigInt), + "text" => Ok(Self::Text), + "timestamp" => Ok(Self::Timestamp), + "inet" => Ok(Self::Inet), + "smallint" => Ok(Self::SmallInt), + "tinyint" => Ok(Self::TinyInt), + "time" => Ok(Self::Time), + "timeuuid" => Ok(Self::Timeuuid), + "uuid" => Ok(Self::Uuid), + "varint" => Ok(Self::Varint), + _ => Err(NativeTypeFromStrError), + } + } +} + #[derive(Clone, Debug, PartialEq, Eq)] enum PreCollectionType { List(Box), From d08f62425a1e8ebed5f0525adaca55b9aff61f59 Mon Sep 17 00:00:00 2001 From: muzarski Date: Thu, 15 Feb 2024 15:30:10 +0100 Subject: [PATCH 2/3] topology: removed usages of strum from ColumnKind Replaced strum crate usage for ColumnKind with our own implemnetation. --- scylla/src/transport/topology.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/scylla/src/transport/topology.rs b/scylla/src/transport/topology.rs index 0907a514e6..667e164fc9 100644 --- a/scylla/src/transport/topology.rs +++ b/scylla/src/transport/topology.rs @@ -26,7 +26,6 @@ use std::num::NonZeroUsize; use std::str::FromStr; use std::sync::Arc; use std::time::{Duration, Instant}; -use strum_macros::EnumString; use tokio::sync::{broadcast, mpsc}; use tracing::{debug, error, trace, warn}; use uuid::Uuid; @@ -348,8 +347,7 @@ pub enum CollectionType { Set(Box), } -#[derive(Clone, Debug, PartialEq, Eq, EnumString)] -#[strum(serialize_all = "snake_case")] +#[derive(Clone, Debug, PartialEq, Eq)] pub enum ColumnKind { Regular, Static, @@ -357,6 +355,24 @@ pub enum ColumnKind { PartitionKey, } +/// [ColumnKind] parse error +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct ColumnKindFromStrError; + +impl std::str::FromStr for ColumnKind { + type Err = ColumnKindFromStrError; + + fn from_str(s: &str) -> Result { + match s { + "regular" => Ok(Self::Regular), + "static" => Ok(Self::Static), + "clustering" => Ok(Self::Clustering), + "partition_key" => Ok(Self::PartitionKey), + _ => Err(ColumnKindFromStrError), + } + } +} + #[derive(Clone, Debug, PartialEq, Eq)] #[allow(clippy::enum_variant_names)] pub enum Strategy { From c463c95b63d00a2f069f9220ea6e58f3f4a4321c Mon Sep 17 00:00:00 2001 From: muzarski Date: Thu, 15 Feb 2024 15:33:02 +0100 Subject: [PATCH 3/3] cargo: remove strum and strum_macros dependencies --- Cargo.lock.msrv | 38 +------------------------------------- scylla/Cargo.toml | 2 -- 2 files changed, 1 insertion(+), 39 deletions(-) diff --git a/Cargo.lock.msrv b/Cargo.lock.msrv index 8e18ce9123..05324b38b0 100644 --- a/Cargo.lock.msrv +++ b/Cargo.lock.msrv @@ -240,7 +240,7 @@ version = "3.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae6371b8bdc8b7d3959e9cf7b22d4435ef3e79e138688421ec654acf8c81b008" dependencies = [ - "heck 0.4.1", + "heck", "proc-macro-error", "proc-macro2", "quote", @@ -656,15 +656,6 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" -[[package]] -name = "heck" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "heck" version = "0.4.1" @@ -1369,12 +1360,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "rustversion" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" - [[package]] name = "rustyline" version = "9.1.2" @@ -1463,8 +1448,6 @@ dependencies = [ "smallvec", "snap", "socket2", - "strum", - "strum_macros", "thiserror", "time", "tokio", @@ -1655,25 +1638,6 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" -[[package]] -name = "strum" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cae14b91c7d11c9a851d3fbc80a963198998c2a64eec840477fa92d8ce9b70bb" - -[[package]] -name = "strum_macros" -version = "0.23.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bb0dc7ee9c15cea6199cde9a127fa16a4c5819af85395457ad72d68edc85a38" -dependencies = [ - "heck 0.3.3", - "proc-macro2", - "quote", - "rustversion", - "syn 1.0.109", -] - [[package]] name = "syn" version = "1.0.109" diff --git a/scylla/Cargo.toml b/scylla/Cargo.toml index dda2d12427..665679c8e7 100644 --- a/scylla/Cargo.toml +++ b/scylla/Cargo.toml @@ -44,8 +44,6 @@ openssl = { version = "0.10.32", optional = true } tokio-openssl = { version = "0.6.1", optional = true } arc-swap = "1.3.0" dashmap = "5.2" -strum = "0.23" -strum_macros = "0.23" lz4_flex = { version = "0.11.1" } smallvec = "1.8.0" async-trait = "0.1.56"