Skip to content

Commit

Permalink
Added custom hasher in one missing place, simplified proc_macro.
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Kirilin <win10@list.ru>
  • Loading branch information
s3rius committed Sep 12, 2023
1 parent e867f03 commit 30c6e12
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions scylla-cql/src/frame/response/cql_to_rust.rs
Expand Up @@ -200,12 +200,12 @@ impl<T: FromCqlVal<CqlValue>> FromCqlVal<CqlValue> for Vec<T> {
}
}

impl<T1: FromCqlVal<CqlValue> + Eq + Hash, T2: FromCqlVal<CqlValue>> FromCqlVal<CqlValue>
for HashMap<T1, T2>
impl<T1: FromCqlVal<CqlValue> + Eq + Hash, T2: FromCqlVal<CqlValue>, T3: BuildHasher + Default>
FromCqlVal<CqlValue> for HashMap<T1, T2, T3>
{
fn from_cql(cql_val: CqlValue) -> Result<Self, FromCqlValError> {
let vec = cql_val.into_pair_vec().ok_or(FromCqlValError::BadCqlType)?;
let mut res = HashMap::with_capacity(vec.len());
let mut res = HashMap::with_capacity_and_hasher(vec.len(), T3::default());
for (key, value) in vec {
res.insert(T1::from_cql(key)?, T2::from_cql(value)?);
}
Expand Down
16 changes: 8 additions & 8 deletions scylla-cql/src/frame/value.rs
Expand Up @@ -853,8 +853,8 @@ impl<T: Value> ValueList for Vec<T> {

// Implement ValueList for maps, which serializes named values
macro_rules! impl_value_list_for_btree_map {
($map_type:ident, $key_type:ty) => {
impl<T: Value> ValueList for $map_type<$key_type, T> {
($key_type:ty) => {
impl<T: Value> ValueList for BTreeMap<$key_type, T> {
fn serialized(&self) -> SerializedResult<'_> {
let mut result = SerializedValues::with_capacity(self.len());
for (key, val) in self {
Expand All @@ -869,8 +869,8 @@ macro_rules! impl_value_list_for_btree_map {

// Implement ValueList for maps, which serializes named values
macro_rules! impl_value_list_for_hash_map {
($map_type:ident, $key_type:ty) => {
impl<T: Value, S: BuildHasher> ValueList for $map_type<$key_type, T, S> {
($key_type:ty) => {
impl<T: Value, S: BuildHasher> ValueList for HashMap<$key_type, T, S> {
fn serialized(&self) -> SerializedResult<'_> {
let mut result = SerializedValues::with_capacity(self.len());
for (key, val) in self {
Expand All @@ -883,10 +883,10 @@ macro_rules! impl_value_list_for_hash_map {
};
}

impl_value_list_for_hash_map!(HashMap, String);
impl_value_list_for_hash_map!(HashMap, &str);
impl_value_list_for_btree_map!(BTreeMap, String);
impl_value_list_for_btree_map!(BTreeMap, &str);
impl_value_list_for_hash_map!(String);
impl_value_list_for_hash_map!(&str);
impl_value_list_for_btree_map!(String);
impl_value_list_for_btree_map!(&str);

// Implement ValueList for tuples of Values of size up to 16

Expand Down

0 comments on commit 30c6e12

Please sign in to comment.