demo/doc / shelf
shelfA 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.
shelf.slot_of(3) == 4
is_slot | Whether a slot number is one a shelf could have. |
label | The label a shelf prints. |
rows | A package-visible helper: pub(pkg) is published surface inside the package and invisible outside it, and the page says which. |
slot_of | The slot a book of width w occupies. |
width_of | The width a slot holds — the inverse of slot_of. |
is_slotfnpubfn 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:
shelf.is_slot("three")
labelfnpubfn 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.
shelf.rows(2) == 2
slot_offnpubfn 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.
shelf.slot_of(0) == 1
shelf.slot_of(7) == 8
width_offnpubfn 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.
let w = shelf.width_of(9)