Skip to content

Commit 7468390

Browse files
committed
types: derive/impl PartialEq and Eq only for test purposes
Implementation of `PartialEq` for `CassDataType` hides a possibly unsafe operation. Let's make sure that we do not depend on it in the code - only use it for test purposes.
1 parent 50f4322 commit 7468390

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

scylla-rust-wrapper/src/cass_types.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ pub(crate) use crate::cass_batch_types::CassBatchType;
1616
pub(crate) use crate::cass_consistency_types::CassConsistency;
1717
pub(crate) use crate::cass_data_types::CassValueType;
1818

19-
#[derive(Clone, Debug, PartialEq, Eq)]
19+
#[derive(Clone, Debug)]
20+
#[cfg_attr(test, derive(PartialEq, Eq))]
2021
pub struct UDTDataType {
2122
// Vec to preserve the order of types
2223
pub field_types: Vec<(String, Arc<CassDataType>)>,
@@ -137,7 +138,8 @@ impl Default for UDTDataType {
137138
}
138139
}
139140

140-
#[derive(Clone, Debug, PartialEq, Eq)]
141+
#[derive(Clone, Debug)]
142+
#[cfg_attr(test, derive(PartialEq, Eq))]
141143
pub enum MapDataType {
142144
Untyped,
143145
Key(Arc<CassDataType>),
@@ -150,7 +152,8 @@ pub struct CassColumnSpec {
150152
pub data_type: Arc<CassDataType>,
151153
}
152154

153-
#[derive(Clone, Debug, PartialEq, Eq)]
155+
#[derive(Clone, Debug)]
156+
#[cfg_attr(test, derive(PartialEq, Eq))]
154157
pub enum CassDataTypeInner {
155158
Value(CassValueType),
156159
UDT(UDTDataType),
@@ -260,11 +263,13 @@ impl CassDataTypeInner {
260263
pub struct CassDataType(UnsafeCell<CassDataTypeInner>);
261264

262265
/// PartialEq and Eq for test purposes.
266+
#[cfg(test)]
263267
impl PartialEq for CassDataType {
264268
fn eq(&self, other: &Self) -> bool {
265269
unsafe { self.get_unchecked() == other.get_unchecked() }
266270
}
267271
}
272+
#[cfg(test)]
268273
impl Eq for CassDataType {}
269274

270275
unsafe impl Sync for CassDataType {}

scylla-rust-wrapper/src/value.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ use crate::cass_types::{CassDataType, CassValueType};
3131
///
3232
/// There is no such method as `cass_statement_bind_counter`, and so
3333
/// we need to serialize the counter value using `CassCqlValue::BigInt`.
34-
#[derive(Clone, Debug, PartialEq)]
34+
#[derive(Clone, Debug)]
35+
#[cfg_attr(test, derive(PartialEq))]
3536
pub enum CassCqlValue {
3637
TinyInt(i8),
3738
SmallInt(i16),

0 commit comments

Comments
 (0)