Expand description
Rustdoc’s HTML rendering module.
This modules contains the bulk of the logic necessary for rendering a
rustdoc clean::Crate instance to a set of static HTML pages. This
rendering process is largely driven by the format! syntax extension to
perform all I/O into files and streams.
The rendering process is largely driven by the Context and Cache
structures. The cache is pre-populated by crawling the crate in question,
and then it is shared among the various rendering threads. The cache is meant
to be a fairly large structure not implementing Clone (because it’s shared
among threads). The context, however, should be a lightweight structure. This
is cloned per-thread and contains information about what is currently being
rendered.
The main entry point to the rendering system is the implementation of
FormatRenderer on Context.
In order to speed up rendering (mostly because of markdown rendering), the
rendering process has been parallelized. This parallelization is only
exposed through the crate method on the context, and then also from the
fact that the shared cache is stored in TLS (and must be accessed as such).
In addition to rendering the crate itself, this module is also responsible for creating the corresponding search index and source file renderings. These threads are not parallelized (they haven’t been a bottleneck yet), and both occur before the crate is rendered.
Re-exports§
use std::borrow::Cow;🔒use std::cmp::Ordering;🔒use std::collections::BTreeMap;🔒use std::collections::VecDeque;🔒use std::fmt;🔒use std::fmt::Display as _;🔒use std::fmt::Write;🔒use std::iter::Peekable;🔒use std::path::PathBuf;🔒use std::fs;🔒use std::str;🔒use askama::Template;🔒use askama::Template;🔒use indexmap::IndexMap;🔒use itertools::Either;🔒use rustc_ast::join_path_syms;🔒use rustc_attr_ir::AttributeKind;🔒use rustc_attr_ir::ConstStability;🔒use rustc_attr_ir::DeprecatedSince;🔒use rustc_attr_ir::Deprecation;🔒use rustc_attr_ir::NotableTraitColor;🔒use rustc_attr_ir::RustcVersion;🔒use rustc_attr_ir::StabilityLevel;🔒use rustc_attr_ir::StableSince;🔒use rustc_attr_ir::find_attr;🔒use rustc_data_structures::fx::FxHashSet;🔒use rustc_data_structures::fx::FxIndexMap;🔒use rustc_data_structures::fx::FxIndexSet;🔒use rustc_hir::Mutability;🔒use rustc_hir::def::DefKind;🔒use rustc_hir::def_id::DefId;🔒use rustc_hir::def_id::DefIdSet;🔒use rustc_middle::ty::print::PrintTraitRefExt;🔒use rustc_middle::ty;🔒use rustc_middle::ty::TyCtxt;🔒use rustc_span::DUMMY_SP;🔒use rustc_span::symbol::Symbol;🔒use rustc_span::symbol::sym;🔒use tracing::debug;🔒use tracing::info;🔒use crate::clean;🔒use crate::clean::Defaultness;🔒use crate::clean::Item;🔒use crate::clean::ItemId;🔒use crate::clean::ItemKind;🔒use crate::clean::RenderedLink;🔒use crate::display::Joined as _;🔒use crate::display::MaybeDisplay as _;🔒use crate::error::Error;🔒use crate::formats::Impl;🔒use crate::formats::cache::Cache;🔒use crate::formats::item_type::ItemType;🔒use crate::html::escape::Escape;🔒use crate::html::format::Ending;🔒use crate::html::format::HrefError;🔒use crate::html::format::HrefInfo;🔒use crate::html::format::PrintWithSpace;🔒use crate::html::format::full_print_fn_decl;🔒use crate::html::format::href;🔒use crate::html::format::print_abi_with_space;🔒use crate::html::format::print_constness_with_space;🔒use crate::html::format::print_generic_bounds;🔒use crate::html::format::print_generics;🔒use crate::html::format::print_impl;🔒use crate::html::format::print_path;🔒use crate::html::format::print_type;🔒use crate::html::format::print_where_clause;🔒use crate::html::format::visibility_print_with_space;🔒use crate::html::markdown::HeadingOffset;🔒use crate::html::markdown::IdMap;🔒use crate::html::markdown::Markdown;🔒use crate::html::markdown::MarkdownItemInfo;🔒use crate::html::markdown::MarkdownSummaryLine;🔒use crate::html::markdown::short_markdown_summary;🔒use crate::html::render::print_item::ImplString;🔒use crate::html::render::search_index::get_function_type_for_search;🔒use crate::html::static_files::SCRAPE_EXAMPLES_HELP_MD;🔒use crate::html::highlight;🔒use crate::html::sources;🔒use crate::scrape_examples::CallData;🔒use crate::scrape_examples::CallLocation;🔒use crate::DOC_RUST_LANG_ORG_VERSION;🔒use crate::try_none;🔒
Modules§
- context 🔒
- flock 🔒
- ordered_
json 🔒 - print_
item 🔒 - search_
index 🔒 - sidebar 🔒
- sorted_
template 🔒 - type_
layout 🔒 - write_
shared 🔒 - Rustdoc writes aut two kinds of shared files:
Structs§
- Alias
Serializable 🔒Impl - Final serialized form of the alias impl
- Aliased
Type 🔒 - Data for an aliased type.
- Aliased
Type 🔒Impl - The
impl_contains data that’s used to figure out if an alias will work, and to generate the HTML at the end. - AllCrates 🔒
- AllCrates
Entry 🔒 - Type of a serialized entry in the
AllCratesPartJSON. - AllTypes 🔒
- Context 🔒
- Major driving force in all rustdoc rendering. This contains information about where in the tree-like hierarchy rendering is occurring and controls how the current page is being rendered.
- Context
Info 🔒 - This struct contains the information that needs to be reset between each
FormatRenderer::itemcall. - Crate
Info 🔒 - Contains pre-rendered contents to insert into the CCI template
- Crates
Index 🔒 - Hierarchy 🔒
- Source files directory tree
- Impl
Rendering 🔒Parameters - Implementor 🔒
- Index
Item 🔒 - Struct representing one entry in the JS search index. These are all emitted by hand to a large JS file at the end of cache-creation.
- Index
Item 🔒Function Type - Full type of functions/methods in the search index.
- Index
Item 🔒Info - Item
Entry 🔒 - Item
Info 🔒 - Notable
Trait 🔒Badge - Part 🔒
- A piece of one of the shared artifacts for documentation (search index, sources, alias list, etc.)
- Parts
AndLocations 🔒 - Paths (relative to the doc root) and their pre-merge contents
- Render
Type 🔒 - A type used for the search index.
- Shared
Context 🔒 - Shared mutable state used in
Contextand elsewhere. - Sidebar
Item 🔒 - Sources 🔒
- Style
Path 🔒 - Trait
Alias 🔒 - Type
Alias 🔒 - Type
Impl 🔒Collector - Collect the list of aliased types and their aliases. https://github.com/search?q=repo%3Arust-lang%2Frust+[RUSTDOCIMPL]+type.impl&type=code
Enums§
- Assoc
Item 🔒Link - Assoc
Item 🔒Render - Specifies whether rendering directly implemented trait items or ones from a certain Deref impl.
- Crate
Info 🔒Version - Version for the format of the crate-info file.
- Item
Section 🔒 - Render
Mode 🔒 - For different handling of associated items from the Deref target of a type rather than the type itself.
- Render
Type 🔒Id - Short
Item 🔒Info
Constants§
Traits§
- CciPart 🔒
- Wrapper trait for
Part<T, U>
Functions§
- assoc_
const 🔒 - assoc_
fn 🔒 - assoc_
href_ 🔒attr - Build a (possibly empty)
hrefattribute (a key-value pair) for the given associated item. - assoc_
ty 🔒 - collect_
paths_ 🔒for_ type - Returns a list of all paths used in the type. This is used to help deduplicate imported impls for reexported types. If any of the contained types are re-exported, we don’t use the corresponding entry from the js file, as inlining will have already picked up the impl
- compute_
if_ 🔒deref_ target_ implements_ copy - create_
parents 🔒 - Create all parents
- document 🔒
- document_
full 🔒 - document_
full_ 🔒collapsible - document_
full_ 🔒inner - document_
item_ 🔒info - Add extra information about an item such as:
- document_
short 🔒 - Writes a documentation block containing only the first paragraph of the documentation. If the docs are longer, a “Read more” link is appended to the end.
- ensure_
trailing_ 🔒slash - extract_
for_ 🔒impl_ name - get_
filtered_ 🔒impls_ for_ reference - Returns the list of implementations for the primitive reference type, filtering out any
implementations that are on concrete or partially generic types, only keeping implementations
of the form
impl<T> Trait for &T. - get_
id_ 🔒for_ impl - get_
path_ 🔒parts - hack_
get_ 🔒external_ crate_ names - Reads
crates.js, which seems like the best place to obtain the list of externally documented crates if the index page was disabled when documenting the deps. - impl_
trait_ 🔒key - is_
notable_ 🔒trait_ passthrough Boxhas pass-through impls forRead,Write,Iterator, andFuturewhen the boxed type implements one of those. We don’t want to treat everyBoxreturn as being notably anIterator(etc), though, so we exempt it.Pinhas the same issue, with a pass-through impl forFuture.- item_
ty_ 🔒to_ section - notable_
trait_ 🔒badges - Returns all
#[doc(notable_trait)]traits thatitemimplements, to be rendered as badges at the top of the item’s page. - notable_
traits_ 🔒button - notable_
traits_ 🔒decl_ for_ item - notable_
traits_ 🔒decl_ for_ type - notable_
traits_ 🔒decl_ write_ html - notable_
traits_ 🔒json - portability 🔒
- read_
template_ 🔒or_ blank - Returns a blank template unless we could find one to append to
- render_
all_ 🔒impls - render_
assoc_ 🔒item - render_
assoc_ 🔒items - render_
assoc_ 🔒items_ inner - render_
attributes_ 🔒in_ code - render_
attributes_ 🔒in_ code_ with_ options - render_
call_ 🔒locations - Generates the HTML for example call locations generated via the –scrape-examples flag.
- render_
code_ 🔒attribute - render_
deref_ 🔒methods derefsis the set of all deref targets that have already been handled.- render_
impl 🔒 - render_
impl_ 🔒summary - render_
impls 🔒 - render_
markdown 🔒 - Render md_text as markdown.
- render_
repr_ 🔒attribute_ in_ code - render_
rightside 🔒 - render_
stability_ 🔒since_ raw - render_
stability_ 🔒since_ raw_ with_ extra - Writes a span containing the versions at which an item became stable and/or const-stable. For example, if the item became stable at 1.0.0, and const-stable at 1.45.0, this function would write a span containing “1.0.0 (const: 1.45.0)”.
- repr_
attribute 🔒 - Compute the public
#[repr]of the item given byDefId. - scrape_
examples_ 🔒help - short_
item_ 🔒info - Render the stability, deprecation and portability information that is displayed at the top of the item’s documentation.
- should_
render_ 🔒item_ for_ deref - since_
to_ 🔒string - small_
url_ 🔒encode - write_
impl_ 🔒section_ heading - write_
not_ 🔒crate_ specific - Writes files that are written directly to the
--out-dir, without the prefix from the current crate. These are the rendered cross-crate files that encode info from multiple crates (e.g. search index), and the static files. - write_
rendered_ 🔒cci - info from this crate and the –include-info-json’d crates
- write_
rendered_ 🔒cross_ crate_ info - write_
resources 🔒 - Writes the static files, the style files, and the css extensions. Have to be careful about these, because they write to the root out dir.
- write_
section_ 🔒heading - write_
shared 🔒