You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is currently possible to derive Message for HashMaps. However it is not possible to use an alternative hashing algorithm like rustc-hash/ahash which may be more optimal in certain situations.
Example
Take a simple Msg message with a int map field. This can be implemented using the default hasher.
use std::collections::HashMap;#[derive(Clone,PartialEq, prost::Message)]pubstructMsg{#[prost(map = "uint32, uint32", tag = "1")]pubmap:HashMap<u32,u32>,}#[test]fndecode(){use prost::Message;constFOO_BYTES:&[u8] = &[10,4,8,3,16,4,10,4,8,1,16,2];let msg = Msg::decode(FOO_BYTES).unwrap();assert_eq!(msg.map.len(),2);assert_eq!(msg.map[&1],2);assert_eq!(msg.map[&3],4);}
However, were I to try to use instead pub map: rustc_hash::FxHashMap<u32, u32> as a more optimal hashing algo for u32 Message derive fails to build as it only implements for the default hasher.
$ cargo build
Compiling prost-alt-hash v0.1.0 (/home/alex/project/prost-alt-hash)
error[E0308]: mismatched types
--> src/lib.rs:3:28
|
3 | #[derive(Clone, PartialEq, prost::Message)]
| ^^^^^^^^^^^^^^
| |
| expected `&HashMap<u32, u32>`, found `&HashMap<u32, u32, ...>`
| arguments to this function are incorrect
|
= note: expected reference `&HashMap<u32, u32>`
found reference `&HashMap<u32, u32, BuildHasherDefault<FxHasher>>`
The text was updated successfully, but these errors were encountered:
It is currently possible to derive
Message
forHashMap
s. However it is not possible to use an alternative hashing algorithm like rustc-hash/ahash which may be more optimal in certain situations.Example
Take a simple
Msg
message with a intmap
field. This can be implemented using the default hasher.However, were I to try to use instead
pub map: rustc_hash::FxHashMap<u32, u32>
as a more optimal hashing algo for u32Message
derive fails to build as it only implements for the default hasher.The text was updated successfully, but these errors were encountered: