pub struct Catalog { /* private fields */ }Expand description
All sections and levels. Iteration, Catalog::next and Catalog::prev follow the
course order, which is numeric on (section, number), whatever order the sections and
levels were declared in.
Implementations§
Source§impl Catalog
impl Catalog
Sourcepub fn new(sections: Vec<Section>) -> Self
pub fn new(sections: Vec<Section>) -> Self
Collect sections into a catalog. Nothing is rejected here (a malformed catalog is
Catalog::validate’s to report), so building one never panics.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&Section, &Level)> + '_
pub fn iter(&self) -> impl Iterator<Item = (&Section, &Level)> + '_
Every level with its section, in course order.
Sourcepub fn ids(&self) -> impl Iterator<Item = LevelId> + '_
pub fn ids(&self) -> impl Iterator<Item = LevelId> + '_
The ids of all levels, in course order.
Sourcepub fn get(&self, id: LevelId) -> Option<(&Section, &Level)>
pub fn get(&self, id: LevelId) -> Option<(&Section, &Level)>
The level with this id and the section it belongs to.
Sourcepub fn next(&self, id: LevelId) -> Result<Option<LevelId>, UnknownLevelError>
pub fn next(&self, id: LevelId) -> Result<Option<LevelId>, UnknownLevelError>
The level after id, or Ok(None) when id is the last one.
Sourcepub fn prev(&self, id: LevelId) -> Result<Option<LevelId>, UnknownLevelError>
pub fn prev(&self, id: LevelId) -> Result<Option<LevelId>, UnknownLevelError>
The level before id, or Ok(None) when id is the first one.
Sourcepub fn resolve_or_nearest(&self, id: LevelId) -> Option<LevelId>
pub fn resolve_or_nearest(&self, id: LevelId) -> Option<LevelId>
Map a possibly stale saved id onto a level that exists.
Levels get renumbered between versions, which would otherwise leave a saved game
permanently unplayable. Resolution keeps the player as close as possible to where
they were: the level itself if it exists, otherwise the nearest later level, and
the last level when the id is past the end. None only for an empty catalog.
Sourcepub fn resolve_str(&self, raw: &str) -> Option<LevelId>
pub fn resolve_str(&self, raw: &str) -> Option<LevelId>
Catalog::resolve_or_nearest for a saved id that may not even parse: a malformed
one resolves to the first level.
Sourcepub fn validate(&self) -> Vec<String>
pub fn validate(&self) -> Vec<String>
Everything wrong with the catalog, as human-readable lines that start with the level
id (or section N). Empty means the catalog is sound.
Structure: unique ids, intro if and only if number 0, every regular level has an
answer or a requirement and a solution. Paths: every declared path is a plain
relative path that does not restate its section root, fixtures do not target their
root. Pairing: cd_evidence needs a cd policy, fd_evidence needs on_fd.
Content: the answer never appears in error, mistake or format messages, a secret
answer never appears in hints or as shellgame submit <answer>, custom at
messages do not name their target, no hint is empty, and every accepts /
rejects example behaves as declared.
Debug builds run this at startup, so a malformed level fails on cargo run.