rustdoc::html::render::context

Struct Context

Source
pub(crate) struct Context<'tcx> {
    pub(crate) current: Vec<Symbol>,
    pub(crate) dst: PathBuf,
    pub(super) render_redirect_pages: bool,
    pub(super) deref_id_map: DefIdMap<String>,
    pub(super) id_map: IdMap,
    pub(crate) shared: Rc<SharedContext<'tcx>>,
    pub(crate) include_sources: bool,
    pub(crate) types_with_notable_traits: FxIndexSet<Type>,
    pub(crate) is_inside_inlined_module: bool,
}
Expand description

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.

It is intended that this context is a lightweight object which can be fairly easily cloned because it is cloned per work-job (about once per item in the rustdoc tree).

Fields§

§current: Vec<Symbol>

Current hierarchy of components leading down to what’s currently being rendered

§dst: PathBuf

The current destination folder of where HTML artifacts should be placed. This changes as the context descends into the module hierarchy.

§render_redirect_pages: bool

A flag, which when true, will render pages which redirect to the real location of an item. This is used to allow external links to publicly reused items to redirect to the right location.

§deref_id_map: DefIdMap<String>

Tracks section IDs for Deref targets so they match in both the main body and the sidebar.

§id_map: IdMap

The map used to ensure all generated ‘id=’ attributes are unique.

§shared: Rc<SharedContext<'tcx>>

Shared mutable state.

Issue for improving the situation: #82381

§include_sources: bool

This flag indicates whether source links should be generated or not. If the source files are present in the html rendering, then this will be true.

§types_with_notable_traits: FxIndexSet<Type>

Collection of all types with notable traits referenced in the current module.

§is_inside_inlined_module: bool

Field used during rendering, to know if we’re inside an inlined item.

Implementations§

Source§

impl<'tcx> Context<'tcx>

Source

pub(crate) fn tcx(&self) -> TyCtxt<'tcx>

Source

pub(crate) fn cache(&self) -> &Cache

Source

pub(super) fn sess(&self) -> &'tcx Session

Source

pub(super) fn derive_id<S: AsRef<str> + ToString>(&mut self, id: S) -> String

Source

pub(super) fn root_path(&self) -> String

String representation of how to get back to the root path of the ‘doc/’ folder in terms of a relative URL.

Source

fn render_item(&mut self, it: &Item, is_module: bool) -> String

Source

fn build_sidebar_items(&self, m: &Module) -> BTreeMap<String, Vec<String>>

Construct a map of items shown in the sidebar to a plain-text summary of their docs.

Source

pub(super) fn src_href(&self, item: &Item) -> Option<String>

Generates a url appropriate for an href attribute back to the source of this item.

The url generated, when clicked, will redirect the browser back to the original source code.

If None is returned, then a source link couldn’t be generated. This may happen, for example, with externally inlined items where the source of their crate documentation isn’t known.

Source

pub(crate) fn href_from_span( &self, span: Span, with_lines: bool, ) -> Option<String>

Source

pub(crate) fn href_from_span_relative( &self, span: Span, relative_to: &str, ) -> Option<String>

Trait Implementations§

Source§

impl<'tcx> FormatRenderer<'tcx> for Context<'tcx>

Generates the documentation for crate into the directory dst

Source§

const RUN_ON_MODULE: bool = true

Whether to call item recursively for modules Read more
Source§

fn descr() -> &'static str

Gives a description of the renderer. Used for performance profiling.
Source§

fn init( krate: Crate, options: RenderOptions, cache: Cache, tcx: TyCtxt<'tcx>, ) -> Result<(Self, Crate), Error>

Sets up any state required for the renderer. When this is called the cache has already been populated.
Source§

fn make_child_renderer(&self) -> Self

Make a new renderer to render a child of the item currently being rendered.
Source§

fn after_krate(&mut self) -> Result<(), Error>

Post processing hook for cleanup and dumping output to files.
Source§

fn mod_item_in(&mut self, item: &Item) -> Result<(), Error>

Renders a module (should not handle recursing into children).
Source§

fn mod_item_out(&mut self) -> Result<(), Error>

Runs after recursively rendering all sub-items of a module.
Source§

fn item(&mut self, item: Item) -> Result<(), Error>

Renders a single non-module item. This means no recursive sub-item rendering is required.
Source§

fn cache(&self) -> &Cache

Auto Trait Implementations§

§

impl<'tcx> Freeze for Context<'tcx>

§

impl<'tcx> !RefUnwindSafe for Context<'tcx>

§

impl<'tcx> !Send for Context<'tcx>

§

impl<'tcx> !Sync for Context<'tcx>

§

impl<'tcx> Unpin for Context<'tcx>

§

impl<'tcx> !UnwindSafe for Context<'tcx>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 192 bytes