rustdoc::html::render::context

Struct Context

Source
pub(crate) struct Context<'tcx> {
    pub(crate) current: Vec<Symbol>,
    pub(crate) dst: PathBuf,
    pub(super) deref_id_map: RefCell<DefIdMap<String>>,
    pub(super) id_map: RefCell<IdMap>,
    pub(crate) shared: SharedContext<'tcx>,
    pub(crate) types_with_notable_traits: RefCell<FxIndexSet<Type>>,
    pub(crate) info: ContextInfo,
}
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.

§deref_id_map: RefCell<DefIdMap<String>>

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

§id_map: RefCell<IdMap>

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

§shared: SharedContext<'tcx>

Shared mutable state.

Issue for improving the situation: #82381

§types_with_notable_traits: RefCell<FxIndexSet<Type>>

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

§info: ContextInfo

Contains information that needs to be saved and reset after rendering an item which is not a module.

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>(&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§

type ModuleData = ContextInfo

This associated type is the type where the current module information is stored. 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 save_module_data(&mut self) -> Self::ModuleData

This method is called right before call Self::item. This method returns a type containing information that needs to be reset after the Self::item method has been called with the Self::restore_module_data method. Read more
Source§

fn restore_module_data(&mut self, info: Self::ModuleData)

Used to reset current module’s information.
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: 2352 bytes