From d541339a239f3d85a2eb3c0c961d152bb4aa24d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Uzarski?= Date: Wed, 11 Dec 2024 12:01:03 +0100 Subject: [PATCH] value: move From conversions after PartialEq and Hash impls I believe this is more readable, and should simplify the diff from the following commit. --- scylla-cql/src/frame/value.rs | 52 +++++++++++++++++------------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/scylla-cql/src/frame/value.rs b/scylla-cql/src/frame/value.rs index a6b6c1c7f..75c557d7b 100644 --- a/scylla-cql/src/frame/value.rs +++ b/scylla-cql/src/frame/value.rs @@ -303,6 +303,32 @@ impl CqlVarint { } } +/// Compares two [`CqlVarint`] values after normalization. +/// +/// # Example +/// +/// ```rust +/// # use scylla_cql::frame::value::CqlVarint; +/// let non_normalized_bytes = vec![0x00, 0x01]; +/// let normalized_bytes = vec![0x01]; +/// assert_eq!( +/// CqlVarint::from_signed_bytes_be(non_normalized_bytes), +/// CqlVarint::from_signed_bytes_be(normalized_bytes) +/// ); +/// ``` +impl PartialEq for CqlVarint { + fn eq(&self, other: &Self) -> bool { + self.as_normalized_slice() == other.as_normalized_slice() + } +} + +/// Computes the hash of normalized [`CqlVarint`]. +impl std::hash::Hash for CqlVarint { + fn hash(&self, state: &mut H) { + self.as_normalized_slice().hash(state) + } +} + #[cfg(feature = "num-bigint-03")] impl From for CqlVarint { fn from(value: num_bigint_03::BigInt) -> Self { @@ -331,32 +357,6 @@ impl From for num_bigint_04::BigInt { } } -/// Compares two [`CqlVarint`] values after normalization. -/// -/// # Example -/// -/// ```rust -/// # use scylla_cql::frame::value::CqlVarint; -/// let non_normalized_bytes = vec![0x00, 0x01]; -/// let normalized_bytes = vec![0x01]; -/// assert_eq!( -/// CqlVarint::from_signed_bytes_be(non_normalized_bytes), -/// CqlVarint::from_signed_bytes_be(normalized_bytes) -/// ); -/// ``` -impl PartialEq for CqlVarint { - fn eq(&self, other: &Self) -> bool { - self.as_normalized_slice() == other.as_normalized_slice() - } -} - -/// Computes the hash of normalized [`CqlVarint`]. -impl std::hash::Hash for CqlVarint { - fn hash(&self, state: &mut H) { - self.as_normalized_slice().hash(state) - } -} - /// Native CQL `decimal` representation. /// /// Represented as a pair: