Overview
msgspec 0.18.5, released on December 12, 2023, adds cache_hash and custom dictionary keys.
Main Features
cache_hash and custom keys
cache_hash=True pre-computes the hash of Structs for efficient use in sets and dictionaries. Dictionary keys can be custom types like enums.
python
import msgspec
class Point(msgspec.Struct, frozen=True, cache_hash=True):
x: int
y: int
# Pre-computed hash: fast in sets
points = {Point(0, 0), Point(1, 1), Point(0, 0)}
print(len(points)) # 2
