Skip to content

Commit

Permalink
value: move From<CqlVarint> conversions after PartialEq and Hash impls
Browse files Browse the repository at this point in the history
I believe this is more readable, and should simplify the diff
from the following commit.
  • Loading branch information
muzarski committed Dec 11, 2024
1 parent 7710af0 commit d541339
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions scylla-cql/src/frame/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<H: std::hash::Hasher>(&self, state: &mut H) {
self.as_normalized_slice().hash(state)
}
}

#[cfg(feature = "num-bigint-03")]
impl From<num_bigint_03::BigInt> for CqlVarint {
fn from(value: num_bigint_03::BigInt) -> Self {
Expand Down Expand Up @@ -331,32 +357,6 @@ impl From<CqlVarint> 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<H: std::hash::Hasher>(&self, state: &mut H) {
self.as_normalized_slice().hash(state)
}
}

/// Native CQL `decimal` representation.
///
/// Represented as a pair:
Expand Down

0 comments on commit d541339

Please sign in to comment.