FFORGE//RS
← Roadmap

rust / LEVEL 4

The rule engine with no vtable

EST.45 MIN
01

THEORY / RETRIEVAL

What to restore

  • Recognize why generic trait methods cannot be dispatched through dyn Trait
  • Fix one input type with an associated type on the trait object
  • Preserve Send and Sync guarantees for a production rule registry

A vtable needs one callable method shape

A method with its own type parameter represents an open family of monomorphized functions, so one trait-object vtable entry cannot describe every instantiation. A receiver such as `&self` plus concrete parameter and return shapes is dyn-compatible. Methods available only when `Self: Sized` may remain generic, but cannot be called through the object.

Associated types can close the object boundary

When every stored rule consumes the same logical input, an associated type states that one-to-one relationship. `dyn Rule<Input = str>` fixes it for the registry while allowing heterogeneous concrete implementations. Static dispatch remains preferable for a known homogeneous hot path; dynamic dispatch is useful when implementations are selected at runtime.

CHECKPOINT

Which method contract can be called through `dyn Rule<Input = str>`?

ISOLATED RUST 1.96
src/lib.rsEDIT

02 / CODE REVIEW

Make the code safe

Repair the rule API so RuleSet stores heterogeneous `Send + Sync` rules behind dynamic dispatch. Introduce one associated input type, bind it to `str` at the object boundary, keep insertion order, and preserve the public constructors and `rejected_by` behavior.

Initializing editor…
CLOUD SANDBOXnetwork off · 256 MB · 12 s
2 / 64 KB
OUTPUT
Runner is waiting for a submission.