Custom Types and Rules-Based Ordering

2025-02-24

I've come up with a system for ordering typelines with custom types (and supporting custom types from the reducer side, but that is another post).

Using the power of Rust features, we can conditionally compile in regex and heck (which are technically unnecessary if we don't support custom types, as every type would be enumerated) so that the problem of Display for an arbitrary CardType still works in the face of custom types. It works by relying on a rules file (the default one is TOML, any serde-supported format is fine), which is converted into regexes and cached to produce and ordering for these types.

A rule looks like

[[creature]]
matchers = [
	{literal = "Medusa-Head"},
	{literal = "Medusa-Hand"},
	{regex = "^Medusa-\\w+$"}
]
precedence = 10

A rule (which applies to a card type: artifact, creature, land, etc.) has 2 parts:

A rules file specifies an exact order using these meta rules:

By enabling feature regex (which will be automatically enabled with the usage of any custom type), this rules-based engine turns on and switches from a Rust-defined ordering algorithm to this rules-based one.