Woke up to an idea that might let me reduce the generic parameters of SexDungeon.
Aaah, this felt good.
let cfg = DungeonMaster::default()
.layout(server.script())
.search_path(search_path)
.seed(&seed);
Previously, this constructed a DungeonMaster object, which stored the layout, search path and seed internally as Option<&whatever>, and had a .build() function that MeansOfProduction::new() called.
As such, if any parameters were missing, that resulted in a run-time error, even though the information is technically available at compile-time.
So I changed DungeonMaster, and it's now a state machine that uses a handful of intermediate types that store a reference to the appropriate things they capture, and those only. Every intermediate type has the same setters, and they transition to the next intermediate type (or the same one, replacing an existing field). If all required types are set, it transitions to a Dungeon (which I will be renaming to Scenario, come to think of it), and thus required parameters are enforced at compile time.
This brought me great joy.
@algernon i will never not love the naming scheme of iocaine code. maybe i should commit to it for bombai as well… i have a few types already somewhat like that but the majority is disgustingly normal
@tudbut I must admit, it is sometimes mighty confusing. There are times when I forget what a particular type is really for.
(But that's a price I'm willing to pay for all the fun when I look at the type names and grin widely.)
Yay!
Turns out I don't need
SexDungeon<REQUEST, RESPONSE, RNG>, onlySexDungeon<REQUEST, RESPONSE>. TheRNGgeneric parameter is only ever used by the constructor, so I simply moved it toMeansOfProduction::new<RNG>().With it being a parameter on a generic function, rather on a generic trait, I could remove all the
PhantomDatas, and a handful of types got therefore simpler.It's also 4 lines less code overall, and reducing code size while maintaining the same functionality is always nice.
Cookie monster!