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: FxHashSet<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 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: FxHashSet<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>
impl<'tcx> Context<'tcx>
pub(crate) fn tcx(&self) -> TyCtxt<'tcx>
pub(crate) fn cache(&self) -> &Cache
pub(super) fn sess(&self) -> &'tcx Session
pub(super) fn derive_id<S: AsRef<str> + ToString>(&mut self, id: S) -> String
sourcepub(super) fn root_path(&self) -> String
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.
fn render_item(&mut self, it: &Item, is_module: bool) -> String
Construct a map of items shown in the sidebar to a plain-text summary of their docs.
sourcepub(super) fn src_href(&self, item: &Item) -> Option<String>
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.
pub(crate) fn href_from_span( &self, span: Span, with_lines: bool, ) -> Option<String>
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>
impl<'tcx> FormatRenderer<'tcx> for Context<'tcx>
Generates the documentation for crate
into the directory dst
source§fn descr() -> &'static str
fn descr() -> &'static str
source§const RUN_ON_MODULE: bool = true
const RUN_ON_MODULE: bool = true
item
recursively for modules Read moresource§fn init(
krate: Crate,
options: RenderOptions,
cache: Cache,
tcx: TyCtxt<'tcx>,
) -> Result<(Self, Crate), Error>
fn init( krate: Crate, options: RenderOptions, cache: Cache, tcx: TyCtxt<'tcx>, ) -> Result<(Self, Crate), Error>
source§fn make_child_renderer(&self) -> Self
fn make_child_renderer(&self) -> Self
source§fn after_krate(&mut self) -> Result<(), Error>
fn after_krate(&mut self) -> Result<(), Error>
source§fn mod_item_in(&mut self, item: &Item) -> Result<(), Error>
fn mod_item_in(&mut self, item: &Item) -> Result<(), Error>
source§fn mod_item_out(&mut self) -> Result<(), Error>
fn mod_item_out(&mut self) -> Result<(), Error>
source§fn item(&mut self, item: Item) -> Result<(), Error>
fn item(&mut self, item: Item) -> Result<(), Error>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moresource§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
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: 160 bytes