hodgepodge
Ready-made Rust enums for lessons, prototypes, and test fixtures. Use colors, calendar names, chemical elements, places, and game pieces to demonstrate iteration, pattern matching, lookup, and serialization with familiar inputs.
Every dataset supports Copy, Clone, PartialEq, Eq, Hash, Display,
FromStr, and an allocation-free as_str(). The default build has no dependencies.
Iteration and serialization are optional.
Version 0.3.0 introduces consistent enum APIs and corrects dataset values. See the migration guide for changes from 0.2, the changelog for release details, and dataset scope for sources and teaching conventions.
Installation
Version 0.3 requires Rust 1.71 or newer. Add it to your dependencies:
[]
= "0.3"
Enable strum for iteration and serde for serialization:
[]
= { = "0.3", = ["strum", "serde"] }
= "1.0"
Parse names and use them as keys
Display and as_str() return the Rust variant name, such as NorthAmerica.
Parsing ignores ASCII case and otherwise requires that complete name. Whitespace,
spaces between words, numeric strings, and abbreviations are rejected; call
trim() explicitly when processing whitespace-delimited input.
use ;
use HashMap;
Work with exact color values
Use rgb() to obtain a packed 0xRRGGBB value from any color enum. Distinct CSS
names can represent the same RGB value. Hex formatting produces six lowercase
digits by default; # adds the Rust 0x prefix.
use CSS;
Color enum discriminants are identifiers. Replace color-to-integer casts with
rgb() when upgrading from 0.2.
Iterate through a dataset
With the strum feature, the helper traits are re-exported by hodgepodge:
use ;
Save and recover fixtures
With the serde feature, enums serialize to their exact variant names. Serde
deserialization is case-sensitive even though FromStr ignores ASCII case.
use DiceFace;
Features
| Feature | Effect |
|---|---|
| Default | Common traits, names, parsing, and color conversions; no dependencies |
strum |
EnumIter, EnumCount, and re-exported helper traits |
enum-iter, enum-count |
Compatibility names that each enable strum |
serde |
Serialize and Deserialize on every dataset |
Complete teaching examples
Run these from the checkout:
lookupparses names and counts visits using enum map keys.palettegroups the 148 CSS names by exact RGB value, exposing aliases.fixturessaves and restores deterministic dice rolls and color names as JSON.
Development
RUSTUP_TOOLCHAIN=1.71.0
RUSTDOCFLAGS="-D warnings"
RUSTDOCFLAGS="-D warnings"
The test script covers standalone and combined features, compatibility feature names, every example target, and documentation tests. Reference fixtures are checked in; tests do not fetch external data.
Licensed under MIT OR Apache-2.0.