Expand description
Compile-time optimized membership checks for static byte sequences.
comtains expands fixed sets of byte strings into zero-allocation,
branch-ordered decision trees. The resulting ByteSet can be embedded
directly into hot parsers, opcode dispatchers, or protocol classifiers
without any runtime preprocessing.
§Example
use comtains::{byte_set, ByteSet};
const KEYWORDS: ByteSet = byte_set![
b"GET",
b"POST",
b"PUT",
b"PATCH",
];
assert!(KEYWORDS.contains(b"POST"));
assert!(!KEYWORDS.contains(b"DELETE"));§Design
- The
byte_set!macro parses string or byte-sequence literals at compile time and builds a trie that merges shared prefixes. - Each branch records how many sequences pass through it; siblings are sorted by descending weight so the hottest paths are checked first.
- The macro emits a nested
matchladder that compares each byte viacandidate.get(depth), returning early on the first mismatch. - Optional debug metadata mirrors the trie structure so unit tests and benchmarks can assert branch ordering.
Modules§
- debug
- Introspection helpers emitted alongside every matcher. Structures describing the generated trie. Intended for tests and debugging.
Macros§
Structs§
- ByteSet
- A compile-time generated byte-set matcher.