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 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>
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>(&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>
Generates the documentation for crate
into the directory dst
impl<'tcx> FormatRenderer<'tcx> for Context<'tcx>
Generates the documentation for crate
into the directory dst
Source§const RUN_ON_MODULE: bool = true
const RUN_ON_MODULE: bool = true
item
recursively for modules Read moreSource§type ModuleData = ContextInfo
type ModuleData = ContextInfo
Source§fn descr() -> &'static str
fn descr() -> &'static str
Source§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 save_module_data(&mut self) -> Self::ModuleData
fn save_module_data(&mut self) -> Self::ModuleData
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 moreSource§fn restore_module_data(&mut self, info: Self::ModuleData)
fn restore_module_data(&mut self, info: Self::ModuleData)
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: 2352 bytes