smalldocs.api_rust
api:
language: rust
manifest: ../Cargo.toml # the crate, from the site’s folder; the root’s Cargo.toml by default
toolchain: nightly # the toolchain that runs rustdoc, which needs -Z unstable-options
private: false # document private items too; a crate with only a binary always does
out: api
source: https://github.com/me/mycrate/blob/main
rustdoc writes what it knows of the crate as JSON. It does not keep the comment after a parameter, so that comment is read from the source, by the lines that the JSON gives. Only the standard library is used.
cargo
cargo(args: list[str], s: Settings, env: dict | None = None, cwd: Path | None = None) -> strRun cargo with the toolchain of the settings; stop with a clear message when cargo or the toolchain is missing, or cargo fails.
| Parameter | Type | Default | Description |
|---|---|---|---|
args |
list[str] | required | The arguments after cargo +TOOLCHAIN |
s |
Settings | required | The settings, for the toolchain |
env |
dict | None | None |
More environment variables |
cwd |
Path | None | None |
The folder cargo runs in |
| returns | str | What cargo wrote to its standard output |
cache_folder
cache_folder() -> PathMake the folder that holds rustdoc’s output and lock files: one per user, that only the user can write, so that no one else can plant files in it.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | Path | The user’s own folder for rustdoc’s output, in the temporary folder |
last_use
last_use(work: Path) -> floatTell when a build last used a crate’s folder: rustdoc writes target/doc each time, and smalldocs 0.5.13 writes manifest.
| Parameter | Type | Default | Description |
|---|---|---|---|
work |
Path | required | A crate’s folder in the cache |
| returns | float | The newest time of its parts that each build writes; 0 when none is there |
gone
gone(work: Path) -> boolTell whether the crate of a folder in the cache is gone, as with a removed worktree.
| Parameter | Type | Default | Description |
|---|---|---|---|
work |
Path | required | A crate’s folder in the cache |
| returns | bool | Whether its mark names a Cargo.toml that is not there; no mark, or one that cannot be read, is never gone |
prune_cache
prune_cache(folder: Path, keep: Path) -> NoneOnce a day, remove the folders of the cache whose Cargo.toml is gone, and those that no build has used for UNUSED_DAYS.
| Parameter | Type | Default | Description |
|---|---|---|---|
folder |
Path | required | The cache, as cache_folder gives it |
keep |
Path | required | The folder of the crate that is being built, which is never removed |
rustdoc
rustdoc(s: Settings, private: bool = False) -> tuple[dict, Path]Run rustdoc on the crate, with its output and its lock file in a temporary folder, so that nothing is written into the project.
| Parameter | Type | Default | Description |
|---|---|---|---|
s |
Settings | required | The settings |
private |
bool | False |
Document private items too |
| returns | tuple[dict, Path] | rustdoc’s JSON of the crate, and the folder its file names start from (the workspace’s root) |
path_text
path_text(p: dict) -> strWrite a path as the source writes it, so that type Result<T> = std::result::Result<T, E> does not read as itself.
| Parameter | Type | Default | Description |
|---|---|---|---|
p |
dict | required | A path of rustdoc’s JSON: path, id and args |
| returns | str | The path as the source writes it, with its generic arguments, such as io::Error or Option<T> |
written_path
written_path(path: str, source: str) -> strFind how the source writes a path: rustdoc gives std::path::Path for a Path that a use brings in, and io::Error as it is.
| Parameter | Type | Default | Description |
|---|---|---|---|
path |
str | required | A path as rustdoc gives it, which may be longer than the source’s, such as std::path::Path for Path |
source |
str | required | The source of the entry that shows it; empty when there is none |
| returns | str | The longest end of the path that the source writes, such as io::Error; the last name when the source writes none |
args_text
args_text(args: dict | str | None) -> strWrite the generic arguments of a path.
| Parameter | Type | Default | Description |
|---|---|---|---|
args |
dict | str | None | required | The generic arguments of a path |
| returns | str | They as Rust writes them, such as <T, Item = u8> or (u8) -> bool |
bounds_text
bounds_text(bounds: list[dict]) -> strWrite a list of bounds, such as Clone + 'a.
| Parameter | Type | Default | Description |
|---|---|---|---|
bounds |
list[dict] | required | The bounds of a generic, a trait or an impl Trait |
| returns | str | They joined by + |
type_text
type_text(t: dict | None) -> strWrite a type as Rust does: &mut [u8], Option<T>, impl Fn(u8) -> bool.
| Parameter | Type | Default | Description |
|---|---|---|---|
t |
dict | None | required | A type of rustdoc’s JSON |
| returns | str | The type as Rust writes it, each path as the entry’s source writes it, or by its last name |
generic_params_text
generic_params_text(params: list[dict]) -> strWrite the generic parameters of an item, without the ones that an impl Trait argument makes.
| Parameter | Type | Default | Description |
|---|---|---|---|
params |
list[dict] | required | The generic parameters of an item |
| returns | str | They in angle brackets, such as <'a, T: Clone>; empty when there are none |
where_text
where_text(generics: dict) -> strWrite the where clause of an item.
| Parameter | Type | Default | Description |
|---|---|---|---|
generics |
dict | required | The generics of an item |
| returns | str | Its where clause, such as where T: Debug; empty when it has none |
visibility
visibility(item: dict, here: str = '', at_root: bool = False) -> strWrite an item’s visibility, as its source does; rustdoc writes a private item as one restricted to its own module, which at the root is crate.
| Parameter | Type | Default | Description |
|---|---|---|---|
item |
dict | required | An item of rustdoc’s JSON |
here |
str | '' |
The id of the module the item is in |
at_root |
bool | False |
Whether that module is the crate’s root |
| returns | str | pub , pub(crate) and so on; empty for a private item, or one in a trait |
self_text
self_text(t: dict) -> strWrite a method’s self parameter as its source does.
| Parameter | Type | Default | Description |
|---|---|---|---|
t |
dict | required | The type of a self parameter |
| returns | str | self, &self, &mut self or self: Box<Self> |
fn_signature
fn_signature(item: dict, name: str, here: str = '', at_root: bool = False, lines: list[str] | None = None) -> strWrite a function’s signature: its visibility, its qualifiers, its generics, its parameters, its return and its where clause.
| Parameter | Type | Default | Description |
|---|---|---|---|
item |
dict | required | A function or method of rustdoc’s JSON |
name |
str | required | Its name |
here |
str | '' |
The id of the module it is in |
at_root |
bool | False |
Whether that module is the crate’s root |
lines |
list[str] | None | None |
The lines of its source file, to show a pattern parameter as written |
| returns | str | Its signature as Rust, on one line, or with a parameter per line when that is long |
split_comment
split_comment(line: str) -> tuple[str, str]Split a line of Rust into its code and its // comment, outside strings, character literals and /* */ comments.
| Parameter | Type | Default | Description |
|---|---|---|---|
line |
str | required | One line of Rust |
| returns | tuple[str, str] | The code before a // comment, and the comment; a doc comment, /// or //!, is no comment here |
signature_lines
signature_lines(lines: list[str], item: dict, name: str) -> list[tuple[str, str, bool, bool]]Find the lines of a function’s signature, from fn NAME to the { that opens its body, or the ; that ends it; the -> of the return is the one outside brackets, generics and the where clause.
| Parameter | Type | Default | Description |
|---|---|---|---|
lines |
list[str] | required | The lines of the source file |
item |
dict | required | A function or method of rustdoc’s JSON, with its span |
name |
str | required | Its name |
| returns | list[tuple[str, str, bool, bool]] | For each line of the signature: its code, its comment, whether it has the ->, and whether it opens the body |
source_params
source_params(lines: list[str], item: dict, name: str) -> list[str]Read each parameter as the source writes it, such as State(state), which rustdoc’s JSON names __arg0 in an async fn and State in another.
| Parameter | Type | Default | Description |
|---|---|---|---|
lines |
list[str] | required | The lines of the source file |
item |
dict | required | A function or method of rustdoc’s JSON, with its span |
name |
str | required | Its name |
| returns | list[str] | The text before the : of each parameter but self, as written; empty when the source does not match the JSON |
without_attributes
without_attributes(text: str) -> strTake out the attributes of a parameter, following brackets and strings to the ] that closes each.
| Parameter | Type | Default | Description |
|---|---|---|---|
text |
str | required | A parameter as written |
| returns | str | It without its attributes, such as #[cfg_attr(all(), doc = "[a]")] |
depth_at
depth_at(text: str, k: int) -> intCount the brackets open before a place in a parameter, so that a : inside a pattern such as S { a: x } is not its type’s.
| Parameter | Type | Default | Description |
|---|---|---|---|
text |
str | required | A parameter as written |
k |
int | required | A place in it |
| returns | int | How many brackets are open there |
param_names
param_names(lines: list[str], item: dict, name: str) -> list[tuple[str, dict, list[str], str]]Name each parameter: rustdoc’s name, unless rustdoc lost the pattern (__arg0, or W for W(x)); then the source’s text. List the names it binds.
| Parameter | Type | Default | Description |
|---|---|---|---|
lines |
list[str] | required | The lines of the source file |
item |
dict | required | A function or method of rustdoc’s JSON |
name |
str | required | Its name in the source |
| returns | list[tuple[str, dict, list[str], str]] | For each parameter but self: the name to show, its type, the names it binds, and its text in the source |
described
described(shown: str, binds: list[str], said: dict[str, str], args: dict[str, str]) -> strFind a parameter’s description: the comment after it, or its # Arguments entry under its name, or the entries of the names its pattern binds.
| Parameter | Type | Default | Description |
|---|---|---|---|
shown |
str | required | A parameter’s name as the page shows it, such as x or State(state) |
binds |
list[str] | required | The names its pattern binds, such as state |
said |
dict[str, str] | required | The comment after each parameter, by its shown name |
args |
dict[str, str] | required | The descriptions of the # Arguments list |
| returns | str | Its description; empty when there is none |
param_pattern
param_pattern(name: str) -> strMake the regular expression that finds a parameter in a signature: name:, mut name:, r#name:, or a pattern with any spacing.
| Parameter | Type | Default | Description |
|---|---|---|---|
name |
str | required | A parameter as rustdoc names it: a, or a pattern such as (b, c) |
| returns | str | A regular expression that finds it before its : in the source |
param_comments
param_comments(lines: list[str], item: dict, name: str) -> tuple[dict[str, str], str]Read the docments of a function: the // comment on a parameter’s line, and the one on the line of -> or of the {.
| Parameter | Type | Default | Description |
|---|---|---|---|
lines |
list[str] | required | The lines of the source file |
item |
dict | required | A function or method of rustdoc’s JSON |
name |
str | required | Its name |
| returns | tuple[dict[str, str], str] | The comment after each parameter, under its name, and the comment on the return |
line_comment
line_comment(lines: list[str], item: dict, shared: set[int] = frozenset()) -> strRead the comment after a field or a variant, such as pub y: f64, // Up, on a line that is its own.
| Parameter | Type | Default | Description |
|---|---|---|---|
lines |
list[str] | required | The lines of the source file |
item |
dict | required | A field or a variant of rustdoc’s JSON, with its span |
shared |
set[int] | frozenset() |
Lines that hold more than this field, such as pub struct P { pub x: u8, pub y: u8 } // a point |
| returns | str | The // comment on its first line or its last; empty when there is none |
section
section(text: str, name: str) -> tuple[list[str], str] | NoneFind a section of a doc comment by its heading, outside code blocks; it runs to the next heading of its level or above.
| Parameter | Type | Default | Description |
|---|---|---|---|
text |
str | required | A doc comment |
name |
str | required | A heading’s text, such as Returns |
| returns | tuple[list[str], str] | None | The section’s lines, and the doc comment without it; None when it has no such section |
returns_section
returns_section(text: str) -> tuple[str, str]Read a # Returns section, the Rust convention for what a function gives back; one paragraph of prose moves into the table, and a longer section stays.
| Parameter | Type | Default | Description |
|---|---|---|---|
text |
str | required | A doc comment |
| returns | tuple[str, str] | What its # Returns section says, on one line for the table, and the doc comment, without the section when the table holds all of it |
arguments_section
arguments_section(text: str) -> tuple[dict[str, str], str]Read a # Arguments list, with lines such as * `a` - the first number, and take it out of the doc comment.
| Parameter | Type | Default | Description |
|---|---|---|---|
text |
str | required | A doc comment |
| returns | tuple[dict[str, str], str] | The description of each parameter in its # Arguments list, and the doc comment without that section |
class Entry
Entry(id: str, name: str, anchor: str, level: int, module: str)One entry on a page: an item, its heading, its anchor and its level.
| Parameter | Type | Default | Description |
|---|---|---|---|
id |
str | required | The item’s id in rustdoc’s JSON |
name |
str | required | The name in its heading, such as Point or Point::distance |
anchor |
str | required | The id of its heading, such as Point.distance |
level |
int | required | The heading level: 2 for an item of the module, 3 for a method |
module |
str | required | The full name of its module, such as mycrate::parse |
class Page
Page(id: str, path: str, file: str = '', entries: list[Entry] = <factory>, reexports: list[tuple[str, str]] = <factory>, modules: list[str] = <factory>)One module’s page: the module, its file name and its entries.
| Parameter | Type | Default | Description |
|---|---|---|---|
id |
str | required | The module’s id in rustdoc’s JSON |
path |
str | required | Its full name, such as mycrate::parse |
file |
str | '' |
The page’s file, from the folder of pages, such as cli/commands/index.qmd |
entries |
list[Entry] | <factory> |
Its entries, in the order of the page |
reexports |
list[tuple[str, str]] | <factory> |
The names it re-exports from elsewhere, with the id of each |
modules |
list[str] | <factory> |
The ids of its own modules |
page_file
page_file(page: Page, taken: set[str] = frozenset()) -> strPlace a module’s page: the crate’s root at mycrate.qmd, a module with modules in a/b/index.qmd, and one without at a/b.qmd.
| Parameter | Type | Default | Description |
|---|---|---|---|
page |
Page | required | A module’s page, with its modules found |
taken |
set[str] | frozenset() |
Pages that someone wrote, which a build never writes over |
| returns | str | Its file, from the folder of pages: the folders follow the modules |
unique
unique(file: str, used: set[str]) -> strGive a page a file that no other page has, such as a module mycrate::mycrate beside the root mycrate.qmd.
| Parameter | Type | Default | Description |
|---|---|---|---|
file |
str | required | A page’s file, from the folder of pages |
used |
set[str] | required | The files that other pages have, in lower case, as a disk may not tell A.qmd from a.qmd; the new file joins it |
| returns | str | The file, or name-module.qmd, name-module-2.qmd and so on when another page has it |
class Crate
Crate(data: dict, root: Path, out: str = 'api', taken: set[str] = frozenset())A crate as rustdoc’s JSON describes it, with a page for each module and an entry for each item.
| Parameter | Type | Default | Description |
|---|---|---|---|
data |
dict | required | rustdoc’s JSON |
root |
Path | required | The folder that the file names of the spans start from |
out |
str | 'api' |
The folder of the pages, inside the site |
taken |
set[str] | frozenset() |
Pages in that folder that someone wrote, from the folder, such as cli/index.qmd |
Crate.field_ids
Crate.field_ids(item: dict) -> list[int]List the ids of the fields of a struct or a union: named, in a tuple, or none.
| Parameter | Type | Default | Description |
|---|---|---|---|
item |
dict | required | A struct or a union |
| returns | list[int] | The ids of the fields that the JSON keeps, in order |
Crate.item
Crate.item(id: str | int) -> dict | NoneFind an item by its id.
| Parameter | Type | Default | Description |
|---|---|---|---|
id |
str | int | required | An item’s id |
| returns | dict | None | The item, or None when the JSON leaves it out |
Crate.kind
Crate.kind(id: str | int) -> strSay what kind of item an id is.
| Parameter | Type | Default | Description |
|---|---|---|---|
id |
str | int | required | An item’s id |
| returns | str | Its kind, such as function or struct; empty when it is not in the JSON |
Crate.walk
Crate.walk(id: str, parents: list[str]) -> NoneMake the page of a module and of each module in it, and give each item its page; a re-exported item from a hidden module joins the page that re-exports it.
| Parameter | Type | Default | Description |
|---|---|---|---|
id |
str | required | A module’s id |
parents |
list[str] | required | The names of the modules it is in |
Crate.claim
Crate.claim(page: Page, id: str) -> boolMake a module, that has no page yet, a module of this page, to be walked after the page’s items.
| Parameter | Type | Default | Description |
|---|---|---|---|
page |
Page | required | A module’s page |
id |
str | required | The id of a module in it, or that it re-exports |
| returns | bool | Whether the module is now one of the page’s modules |
Crate.adopt
Crate.adopt(page: Page, id: str, seen: set[str]) -> NoneGive a re-exported item an entry on this page when it has no page of its own yet; otherwise list it as a re-export.
| Parameter | Type | Default | Description |
|---|---|---|---|
page |
Page | required | The page of the module that has the pub use |
id |
str | required | The id of the use item |
seen |
set[str] | required | The hidden modules whose items a glob has already brought here, so that a cycle of globs ends |
Crate.public_home
Crate.public_home(id: str) -> str | NoneSay whether an item will have an entry where it is defined, so that a re-export of it is only a link.
| Parameter | Type | Default | Description |
|---|---|---|---|
id |
str | required | An item’s id |
| returns | str | None | The module it is defined in, when that module has a page of its own; otherwise None |
Crate.place
Crate.place(page: Page, id: str, name: str | None = None) -> NoneGive an item its entry on a page, with the entries of its methods under it.
| Parameter | Type | Default | Description |
|---|---|---|---|
page |
Page | required | The page the item goes on |
id |
str | required | The item’s id |
name |
str | None | None |
The name it has there, when a pub use ... as renames it |
Crate.members
Crate.members(id: str) -> list[tuple[str, str]]List the methods of a type’s own impl blocks, or the items of a trait.
| Parameter | Type | Default | Description |
|---|---|---|---|
id |
str | required | The id of a struct, an enum, a union or a trait |
| returns | list[tuple[str, str]] | The id and the name of each method and associated item that gets an entry under it |
Crate.trait_impls
Crate.trait_impls(id: str) -> list[dict]List the traits a type implements in its own code, or derives.
| Parameter | Type | Default | Description |
|---|---|---|---|
id |
str | required | The id of a struct, an enum or a union |
| returns | list[dict] | The paths of the traits it implements; not the auto traits, such as Send, nor the blanket impls, such as From<T> |
Crate.source
Crate.source(item: dict) -> list[str]Read the lines of an item’s source file, once per file.
| Parameter | Type | Default | Description |
|---|---|---|---|
item |
dict | required | An item with a span |
| returns | list[str] | The lines of its source file; empty when the file cannot be read |
Crate.url
Crate.url(id: str | int | None) -> str | NoneFind where an item is documented: on a page of this site, or in the docs of another crate.
| Parameter | Type | Default | Description |
|---|---|---|---|
id |
str | int | None | required | An item’s id, from a link or a path |
| returns | str | None | A link to its entry, to its page, or to the docs of the crate it is from; None when it has none |
Crate.external_url
Crate.external_url(id: str) -> str | NoneLink an item of another crate to its docs, as rustdoc’s pages do.
| Parameter | Type | Default | Description |
|---|---|---|---|
id |
str | required | The id of an item of another crate |
| returns | str | None | A link to its page in that crate’s docs: its html_root_url, or docs.rs |
Crate.external_kind
Crate.external_kind(path: list[str], crate_id: int) -> strFind the kind of another crate’s item by its path, to link a method on its type’s page.
| Parameter | Type | Default | Description |
|---|---|---|---|
path |
list[str] | required | The full path of an item of another crate |
crate_id |
int | required | The crate’s id |
| returns | str | The item’s kind; empty when the JSON does not list it |
fence_run
fence_run(stripped: str) -> strFind the fence mark a line starts with.
| Parameter | Type | Default | Description |
|---|---|---|---|
stripped |
str | required | A line of Markdown, without its indent |
| returns | str | The run of three or more backticks or tildes it starts with, such as “````”; empty when it starts no fence |
closes
closes(stripped: str, fence: str) -> boolTell whether a line closes a fenced code block, as CommonMark says.
| Parameter | Type | Default | Description |
|---|---|---|---|
stripped |
str | required | A line of Markdown, without its indent, inside a fence |
fence |
str | required | The mark that opened the fence |
| returns | bool | Whether the line closes it: as many marks of the same kind or more, and nothing after |
link_docs
link_docs(text: str, links: dict[str, int], crate: Crate) -> strTurn the intra-doc links of a doc comment, such as [`Parser`], into links to their entries.
| Parameter | Type | Default | Description |
|---|---|---|---|
text |
str | required | A doc comment, as Markdown |
links |
dict[str, int] | required | rustdoc’s links of the item: the target as written, and the id it resolves to |
crate |
Crate | required | The crate |
| returns | str | The same Markdown with each intra-doc link made a link to its entry |
tidy_docs
tidy_docs(text: str, shift: int) -> strMake a doc comment fit a page: its headings under the entry’s, a code block with no language as Rust, and no lines hidden with # .
| Parameter | Type | Default | Description |
|---|---|---|---|
text |
str | required | A doc comment, as Markdown |
shift |
int | required | How many levels to move its headings down, so that they sit under the entry’s heading |
| returns | str | The same Markdown, with its headings moved down and its Rust examples as rustdoc shows them |
summary
summary(text: str) -> strRead the summary of a doc comment: its first paragraph.
| Parameter | Type | Default | Description |
|---|---|---|---|
text |
str | required | A doc comment |
| returns | str | Its first paragraph on one line, with links as their text; empty when it starts with a heading or code |
source_link
source_link(s: Settings, crate: Crate, item: dict) -> strLink an item to the line that defines it.
| Parameter | Type | Default | Description |
|---|---|---|---|
s |
Settings | required | The settings |
crate |
Crate | required | The crate |
item |
dict | required | An item with a span |
| returns | str | A Markdown link to its first line, or empty when there is no source or the file is not in the repository |
code
code(text: str) -> strPut Rust code in a code block.
| Parameter | Type | Default | Description |
|---|---|---|---|
text |
str | required | Rust code |
| returns | str | It in a rust code block |
fn_table
fn_table(crate: Crate, item: dict, args: dict[str, str], gives: str = '') -> strDescribe a function by its parameters and its return: the type and the comment of each.
| Parameter | Type | Default | Description |
|---|---|---|---|
crate |
Crate | required | The crate |
item |
dict | required | A function or method |
args |
dict[str, str] | required | The descriptions of its # Arguments list |
gives |
str | '' |
The text of its # Returns section |
| returns | str | A Markdown table of its parameters and its return: type, description |
fields_of
fields_of(crate: Crate, item: dict) -> list[tuple[str, dict]]List the fields of a struct or a union.
| Parameter | Type | Default | Description |
|---|---|---|---|
crate |
Crate | required | The crate |
item |
dict | required | A struct or a union |
| returns | list[tuple[str, dict]] | The name and the item of each field that the JSON keeps, in order |
describe
describe(crate: Crate, item: dict) -> strDescribe a field or a variant: its doc comment, with its links, or the comment after it, on a line that holds only it.
| Parameter | Type | Default | Description |
|---|---|---|---|
crate |
Crate | required | The crate |
item |
dict | required | A field or a variant |
| returns | str | Its doc comment on one line, or else the comment after it |
variant_text
variant_text(crate: Crate, item: dict) -> strWrite a variant of an enum.
| Parameter | Type | Default | Description |
|---|---|---|---|
crate |
Crate | required | The crate |
item |
dict | required | A variant |
| returns | str | It as Rust writes it, such as Rgb(u8, u8, u8) or Named { name: String } |
item_signature
item_signature(crate: Crate, item: dict, name: str, here: str = '') -> strWrite the declaration of a struct, an enum, a trait, a type, a constant, a static or a macro.
| Parameter | Type | Default | Description |
|---|---|---|---|
crate |
Crate | required | The crate |
item |
dict | required | An item that is not a function |
name |
str | required | The name it has on the page |
here |
str | '' |
The id of the module it is in |
| returns | str | Its declaration as Rust, without its body |
written_value
written_value(lines: list[str], item: dict) -> strRead the value of a constant or a static from its source, when rustdoc gives _, as it does for an array such as ["a", "b"].
| Parameter | Type | Default | Description |
|---|---|---|---|
lines |
list[str] | required | The lines of the source file |
item |
dict | required | A constant or a static, with its span |
| returns | str | Its value as the source writes it, without comments; empty when it cannot be read |
impl_line
impl_line(crate: Crate, id: str) -> strList the traits a type implements, each by its name, linked to its docs.
| Parameter | Type | Default | Description |
|---|---|---|---|
crate |
Crate | required | The crate |
id |
str | required | The id of a struct, an enum or a union |
| returns | str | A line such as “Implements Display, Clone.”, with links; empty when it implements no trait itself |
implementors_line
implementors_line(crate: Crate, item: dict) -> strList the types of the crate that implement a trait.
| Parameter | Type | Default | Description |
|---|---|---|---|
crate |
Crate | required | The crate |
item |
dict | required | A trait |
| returns | str | A line such as “Implemented for Circle.”, with links; empty when nothing in the crate implements it |
item_source
item_source(crate: Crate, item: dict) -> strRead the code of an item, to show its paths as it writes them; a function’s body is left out, as its paths are not its signature’s.
| Parameter | Type | Default | Description |
|---|---|---|---|
crate |
Crate | required | The crate |
item |
dict | required | An item with a span |
| returns | str | Its source without comments: a function’s signature, or the whole of any other item; empty when it cannot be read |
entry_markdown
entry_markdown(s: Settings, crate: Crate, e: Entry) -> strWrite one entry, with each path in it as the entry’s source writes it.
| Parameter | Type | Default | Description |
|---|---|---|---|
s |
Settings | required | The settings |
crate |
Crate | required | The crate |
e |
Entry | required | One entry |
| returns | str | Its Markdown: heading, source link, signature, doc comment and tables |
entry_parts
entry_parts(s: Settings, crate: Crate, e: Entry) -> strWrite one entry: a heading with its id, a source link, the signature, the doc comment and the table of its parameters, fields or variants.
| Parameter | Type | Default | Description |
|---|---|---|---|
s |
Settings | required | The settings |
crate |
Crate | required | The crate |
e |
Entry | required | One entry |
| returns | str | Its Markdown: heading, source link, signature, doc comment and tables |
page_markdown
page_markdown(s: Settings, crate: Crate, page: Page) -> strWrite one module’s page: front matter, the module’s doc comment, its modules and re-exports, then an entry for each item.
| Parameter | Type | Default | Description |
|---|---|---|---|
s |
Settings | required | The settings |
crate |
Crate | required | The crate |
page |
Page | required | One module’s page |
| returns | str | The text of its .qmd page |
modules_table
modules_table(crate: Crate, pages: list[Page]) -> strList some modules, each by its own name, linked to its page, with its summary.
| Parameter | Type | Default | Description |
|---|---|---|---|
crate |
Crate | required | The crate |
pages |
list[Page] | required | The pages of some modules |
| returns | str | A Markdown table with a link to each, by its name, and its summary |
symbols
symbols(crate: Crate) -> dict[str, str]Make the index of names that links use: Point, Point::distance, Point.distance and mycrate::Point::distance.
| Parameter | Type | Default | Description |
|---|---|---|---|
crate |
Crate | required | The crate |
| returns | dict[str, str] | Each name, under its short form and its full path, with the link to its entry |
load
load(s: Settings, private: bool = False, taken: set[str] = frozenset()) -> CrateRun rustdoc and read its JSON.
| Parameter | Type | Default | Description |
|---|---|---|---|
s |
Settings | required | The settings |
private |
bool | False |
Document private items too |
taken |
set[str] | frozenset() |
Pages that someone wrote in the folder of pages |
| returns | Crate | The crate, read from rustdoc’s JSON |
build
build(s: Settings) -> list[Path]Write a reference page per module of the crate, in folders that follow the modules, an index.qmd for each folder with none, and _symbols.json.
| Parameter | Type | Default | Description |
|---|---|---|---|
s |
Settings | required | The settings |
| returns | list[Path] | The pages written |
entry_gaps
entry_gaps(crate: Crate, e: Entry) -> list[str]Find what one entry is missing: a doc comment, a docment for a parameter or the return, or a comment for a field or a variant.
| Parameter | Type | Default | Description |
|---|---|---|---|
crate |
Crate | required | The crate |
e |
Entry | required | One entry |
| returns | list[str] | One message per gap; empty when the entry is documented |
check
check(s: Settings, shown: bool = False) -> intPrint how much of each module is documented, then every gap, then the total.
| Parameter | Type | Default | Description |
|---|---|---|---|
s |
Settings | required | The settings |
shown |
bool | False |
Hold the crate only to what its pages show; otherwise its private items too |
| returns | int | The exit code: 0 when nothing is missing, 1 otherwise |