#hash #match #proc-macro #macro #compile-time #build #collision

macro match-by-hash

Match statement, but for any value and with a hash function

3 releases (stable)

1.0.1 Dec 15, 2023
0.1.0 Dec 15, 2023

#645 in Procedural macros

45 downloads per month

MIT license

7KB
136 lines

Need to match one string among many? Or maybe not even strings, but something else in large quantities? Then this crate is for you.

Features

  • Supports custom hash functions. However, only those that can be evaluated at compile time.
  • Key types get compared with == to check if the key is right.
  • It also checks at compile time for hash collisions (but only in debug builds).

Notes

  • This macro is unable to come up with perfect hash function on its own. If you see errors due to collisions, then you're gonna need a better hash function.

Dependencies

~320–770KB
~18K SLoC