Crate comtains

Crate comtains 

Source
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

  1. The byte_set! macro parses string or byte-sequence literals at compile time and builds a trie that merges shared prefixes.
  2. Each branch records how many sequences pass through it; siblings are sorted by descending weight so the hottest paths are checked first.
  3. The macro emits a nested match ladder that compares each byte via candidate.get(depth), returning early on the first mismatch.
  4. 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§

byte_set
Build a ByteSet from compile-time byte sequences.

Structs§

ByteSet
A compile-time generated byte-set matcher.