From 8bf32be7d42ff28ab6274ce6c211ef3b9d83b174 Mon Sep 17 00:00:00 2001 From: plodsoft Date: Fri, 11 Aug 2023 11:05:04 +0800 Subject: [PATCH] feat(napi): impl FromNapiValue for HashMap with custom hasher (#1682) --- crates/napi/src/bindgen_runtime/js_values/map.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/napi/src/bindgen_runtime/js_values/map.rs b/crates/napi/src/bindgen_runtime/js_values/map.rs index 6e0c4748..1a7e8c28 100644 --- a/crates/napi/src/bindgen_runtime/js_values/map.rs +++ b/crates/napi/src/bindgen_runtime/js_values/map.rs @@ -1,5 +1,5 @@ use std::collections::HashMap; -use std::hash::Hash; +use std::hash::{BuildHasher, Hash}; use crate::bindgen_prelude::{Env, Result, ToNapiValue, *}; @@ -31,14 +31,15 @@ where } } -impl FromNapiValue for HashMap +impl FromNapiValue for HashMap where K: From + Eq + Hash, V: FromNapiValue, + S: Default + BuildHasher, { unsafe fn from_napi_value(env: sys::napi_env, napi_val: sys::napi_value) -> Result { let obj = unsafe { Object::from_napi_value(env, napi_val)? }; - let mut map = HashMap::new(); + let mut map = HashMap::default(); for key in Object::keys(&obj)?.into_iter() { if let Some(val) = obj.get(&key)? { map.insert(K::from(key), val);