Skip to main content

Catalog

Struct Catalog 

Source
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

Source

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.

Source

pub fn len(&self) -> usize

The number of levels.

Source

pub fn is_empty(&self) -> bool

True when there are no levels.

Source

pub fn iter(&self) -> impl Iterator<Item = (&Section, &Level)> + '_

Every level with its section, in course order.

Source

pub fn ids(&self) -> impl Iterator<Item = LevelId> + '_

The ids of all levels, in course order.

Source

pub fn sections(&self) -> &[Section]

The sections, ordered by number.

Source

pub fn section(&self, number: u16) -> Option<&Section>

The section with this number.

Source

pub fn get(&self, id: LevelId) -> Option<(&Section, &Level)>

The level with this id and the section it belongs to.

Source

pub fn first(&self) -> Option<LevelId>

The first level of the course.

Source

pub fn last(&self) -> Option<LevelId>

The last level of the course.

Source

pub fn next(&self, id: LevelId) -> Result<Option<LevelId>, UnknownLevelError>

The level after id, or Ok(None) when id is the last one.

Source

pub fn prev(&self, id: LevelId) -> Result<Option<LevelId>, UnknownLevelError>

The level before id, or Ok(None) when id is the first one.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Catalog

Source§

fn clone(&self) -> Catalog

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Catalog

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> IntoIterator for &'a Catalog

Source§

type Item = (&'a Section, &'a Level)

The type of the elements being iterated over.
Source§

type IntoIter = Box<dyn Iterator<Item = (&'a Section, &'a Level)> + 'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.