Skip to main content

Crate hodgepodge

Crate hodgepodge 

Source
Expand description

§Hodgepodge

hodgepodge bundles ready-made enums you can drop into lessons, prototypes, demos, and coding exercises. Each enum doubles as a small dataset (CSS color keywords, RGB swatches, the periodic table, geography trivia, game pieces, etc.) so you can focus on explaining a concept instead of inventing sample data.

Bring everything into scope with use hodgepodge::*;, then iterate over the variants through ALL (or with the strum feature), format their values, or serialize them (with the serde feature) depending on what the example calls for.

§Names, equality, and lookup

Every enum dataset implements Copy, Clone, PartialEq, Eq, Hash, Display, and FromStr. as_str() and Display return the Rust variant name. Parsing ignores ASCII case but requires the complete name without whitespace. These operations require no optional features or runtime dependencies. Every enum dataset also exposes ALL, COUNT, and a human-readable label(), with generic access through Dataset.

use hodgepodge::{Month, CSS};

let month: Month = "september".parse()?;
assert_eq!(month, Month::September);
assert_eq!(month.to_string(), "September");
assert_eq!(CSS::Aqua.rgb(), CSS::Cyan.rgb());
assert_ne!(CSS::Aqua, CSS::Cyan); // Different names, identical colors.

§Dataset scope

Reference fixtures cover chemistry, geography, anatomy, ecology, and geologic time. Bone counts use the conventional 206-bone adult skeleton; muscle names are a teaching selection. Consult each enum’s documentation for its scope.

§Feature-gated helpers

  • strum – enables iteration and variant counts for every dataset, re-exporting IntoEnumIterator and EnumCount so you can use these traits without depending on strum directly.

  • enum-iter / enum-count – legacy compatibility feature names that now simply forward to strum.

  • serde – enables serde::Serialize and serde::Deserialize so the enums and cards can be persisted in fixtures for tutorials or quick prototypes.

  • rand – uniform variant sampling and card shuffling with a caller-supplied rand 0.9 RNG. Samples use replacement; consume a shuffled deck to deal unique cards.

  • taxonomy – a shared Species enum with hierarchical aliases, backed by source records, ancestry, intermediate ranks, and Wikipedia links; see the taxonomy module when enabled. The data carries CC BY 4.0 attribution in addition to the software license.

§Examples

§Iterate through datasets

use hodgepodge::{Element, IntoEnumIterator};

for element in Element::iter() {
    let atomic_number = element.atomic_number();
    println!("{element:?} is element {atomic_number}");
}

§Format CSS color hex values

use hodgepodge::CSS;

let swatch = CSS::Tomato;
println!("{swatch:?} renders as #{swatch:06x}");

§Serialize and deserialize enums

use hodgepodge::Day;

let json = serde_json::to_string(&Day::Friday).expect("serialize Day");
let day: Day = serde_json::from_str(&json).expect("deserialize Day");
assert_eq!(day, Day::Friday);

§Work with seasons and fiscal quarters

use hodgepodge::{Quarter, Season};

let midyear = Season::Summer;
let fiscal = Quarter::Q4;

assert_eq!(midyear as u8, 3);
assert_eq!(fiscal as u8, 4);

Re-exports§

pub use metadata::DatasetCoverage;
pub use metadata::DatasetInfo;
pub use metadata::DatasetSource;
pub use metadata::DATASETS;
pub use colors::*;
pub use science::*;
pub use geography::*;
pub use time::*;
pub use games::*;
pub use misc::*;
pub use biology::*;
pub use anatomy::*;
pub use ecology::*;
pub use geology::*;
pub use literature::*;

Modules§

anatomy
Individual adult bones and selected skeletal muscle types. The conventional adult skeleton and a selected set of skeletal muscles.
biology
DNA/RNA bases, standard-code codons, and the twenty standard amino acids. DNA bases and the twenty standard proteinogenic amino acids.
colors
Color palettes ranging from ROYGBIV to CSS keywords. Color datasets ranging from rainbow mnemonics (ROYGBIV) to CMYK, RGB, and CSS keyword lists. Use rgb() for packed RGB values; enum discriminants are identifiers and do not represent colors.
ecology
Terrestrial biome categories. Terrestrial habitat categories using the WWF biome convention.
games
Games and leisure datasets like playing card suits and ranks. Game-centric datasets such as playing card suits and ranks.
geography
Geographic datasets covering continents, regions, and states. Geographic datasets covering directions, continents, and civic regions.
geology
Rocks, Earth layers, and the hierarchy of geologic time. Rocks, Earth structure, atmosphere layers, and geologic time.
literature
Literary datasets such as Dante’s circles of Hell. Literary datasets with explicit source-specific conventions.
metadata
Provenance and scope shared by the library’s enum datasets.
misc
Miscellaneous grab-bag datasets for playful examples. Miscellaneous datasets such as medals, ordinals, and programming trivia.
science
Science-themed datasets such as planets and SI prefixes. Science datasets such as metric units, SI prefixes, planets, and elements.
taxonomy
A sourced animal taxonomy with parent/child traversal and Wikipedia links. A versioned animal taxonomy, enabled by the taxonomy feature.
time
Temporal datasets including months and weekdays. Timekeeping datasets including weekdays and months.

Structs§

EnumValueError
An integer outside the values represented by a numeric dataset.
ParseEnumError
A string did not match a variant of the requested dataset.

Traits§

Dataset
Metadata shared by every enum dataset, without optional features.
EnumCount
Re-export helper traits from strum when the relevant feature is enabled. A trait for capturing the number of variants in Enum. This trait can be autoderived by strum_macros.
IntoEnumIterator
Re-export helper traits from strum when the relevant feature is enabled. This trait designates that an Enum can be iterated over. It can be auto generated using the EnumIter derive macro.