demo/doc / shelf

shelf

A shelf of numbered slots — the s53 documentation fixture.

This module exists to be documented, so it exercises every part of the doc surface at once: a module //! block with prose and a doctest, /// comments with summary sentences, an intra-doc link to slot_of, every fence directive, and a pub(pkg) item that a default run publishes and a --private run joins with the private one below.

doctest

shelf.slot_of(3) == 4

Items

is_slotWhether a slot number is one a shelf could have.
labelThe label a shelf prints.
rowsA package-visible helper: pub(pkg) is published surface inside the package and invisible outside it, and the page says which.
slot_ofThe slot a book of width w occupies.
width_ofThe width a slot holds — the inverse of slot_of.

is_slotfnpub

fn is_slot(s: int) -> bool

Whether a slot number is one a shelf could have.

Passing a string where an int belongs is refused, and this fence asserts the refusal rather than describing it:

doctestmust be refused: E0401

shelf.is_slot("three")

labelfnpub

fn label(s: int) -> int

The label a shelf prints. The fence here is prose in a fence — a shape, not a program — so it carries ignore.

<slot>: <title> (<width>)

rowsfnpub(pkg)

fn rows(n: int) -> int

A package-visible helper: pub(pkg) is published surface inside the package and invisible outside it, and the page says which.

doctest

shelf.rows(2) == 2

slot_offnpub

fn slot_of(w: int) -> int

The slot a book of width w occupies. The first sentence ends here, and everything after it is the body — which is how a listing can be one line while a page is a page.

A shelf is one-indexed, so the answer is always at least 1. See width_of for the inverse, and shelf.slot_of for this same function named the long way.

doctest

shelf.slot_of(0) == 1
shelf.slot_of(7) == 8

width_offnpub

fn width_of(s: int) -> int

The width a slot holds — the inverse of slot_of.

The fence below is compiled and never executed: it demonstrates the shape of a call whose value nobody wants.

doctestcompiled, not run

let w = shelf.width_of(9)