Skip to main content

## Cache

# Struct Cache

Source

    pub(crate) struct Cache {Show 21 fields
        pub(crate) impls: DefIdMap<Vec<Impl>>,
        pub(crate) paths: FxIndexMap<DefId, (Vec<Symbol>, ItemType)>,
        pub(crate) external_paths: FxIndexMap<DefId, (Vec<Symbol>, ItemType)>,
        pub(crate) exact_paths: DefIdMap<Vec<Symbol>>,
        pub(crate) traits: FxIndexMap<DefId, Trait>,
        pub(crate) implementors: FxIndexMap<DefId, Vec<Impl>>,
        pub(crate) extern_locations: FxIndexMap<CrateNum, ExternalLocation>,
        pub(crate) primitive_locations: FxIndexMap<PrimitiveType, DefId>,
        pub(crate) effective_visibilities: RustdocEffectiveVisibilities,
        pub(crate) crate_version: Option<String>,
        pub(crate) document_private: bool,
        pub(crate) document_hidden: bool,
        pub(crate) masked_crates: FxHashSet<CrateNum>,
        stack: Vec<Symbol>,
        parent_stack: Vec<ParentStackItem>,
        stripped_mod: bool,
        pub(crate) search_index: Vec<IndexItem>,
        pub(crate) orphan_impl_items: Vec<OrphanImplItem>,
        orphan_trait_impls: Vec<(DefId, FxIndexSet<DefId>, Impl)>,
        pub(crate) intra_doc_links: FxHashMap<ItemId, FxIndexSet<ItemLink>>,
        pub(crate) inlined_items: DefIdSet,
    }

Expand description

This cache is used to store information about the `clean::Crate` being rendered in order to provide more useful documentation. This contains information like all implementors of a trait, all traits a type implements, documentation for all known traits, etc.

This structure purposefully does not implement `Clone` because it’s intended to be a fairly large and expensive structure to clone. Instead this adheres to `Send` so it may be stored in an `Arc` instance and shared among the various rendering threads.

## Fields§

§`impls: DefIdMap<Vec<Impl>>`

Maps a type ID to all known implementations for that type. This is only recognized for intra-crate `clean::Type::Path`s, and is used to print out extra documentation on the page of an enum/struct.

The values of the map are a list of implementations and documentation found on that implementation.

§`paths: FxIndexMap<DefId, (Vec<Symbol>, ItemType)>`

Maintains a mapping of local crate `DefId`s to the fully qualified name and “short type description” of that node. This is used when generating URLs when a type is being linked to. External paths are not located in this map because the `External` type itself has all the information necessary.

§`external_paths: FxIndexMap<DefId, (Vec<Symbol>, ItemType)>`

Similar to `paths`, but only holds external paths. This is only used for generating explicit hyperlinks to other crates.

§`exact_paths: DefIdMap<Vec<Symbol>>`

Maps local `DefId`s of exported types to fully qualified paths. Unlike ‘paths’, this mapping ignores any renames that occur due to ‘use’ statements.

This map is used when writing out the `impl.trait` and `impl.type` javascript files. By using the exact path that the type is declared with, we ensure that each path will be identical to the path used if the corresponding type is inlined. By doing this, we can detect duplicate impls on a trait page, and only display the impl for the inlined type.

§`traits: FxIndexMap<DefId, Trait>`

This map contains information about all known traits of this crate. Implementations of a crate should inherit the documentation of the parent trait if no extra documentation is specified, and default methods should show up in documentation about trait implementations.

§`implementors: FxIndexMap<DefId, Vec<Impl>>`

When rendering traits, it’s often useful to be able to list all implementors of the trait, and this mapping is exactly, that: a mapping of trait ids to the list of known implementors of the trait

§`extern_locations: FxIndexMap<CrateNum, ExternalLocation>`

Cache of where external crate documentation can be found.

§`primitive_locations: FxIndexMap<PrimitiveType, DefId>`

Cache of where documentation for primitives can be found.

§`effective_visibilities: RustdocEffectiveVisibilities`§`crate_version: Option<String>`

The version of the crate being documented, if given from the `--crate-version` flag.

§`document_private: bool`

Whether to document private items. This is stored in `Cache` so it doesn’t need to be passed through all rustdoc functions.

§`document_hidden: bool`

Whether to document hidden items. This is stored in `Cache` so it doesn’t need to be passed through all rustdoc functions.

§`masked_crates: FxHashSet<CrateNum>`

Crates marked with `#[doc(masked)]`.

§`stack: Vec<Symbol>`§`parent_stack: Vec<ParentStackItem>`§`stripped_mod: bool`§`search_index: Vec<IndexItem>`§`orphan_impl_items: Vec<OrphanImplItem>`§`orphan_trait_impls: Vec<(DefId, FxIndexSet<DefId>, Impl)>`§`intra_doc_links: FxHashMap<ItemId, FxIndexSet<ItemLink>>`

All intra-doc links resolved so far.

Links are indexed by the DefId of the item they document.

§`inlined_items: DefIdSet`

Contains the list of `DefId`s which have been inlined. It is used when generating files to check if a stripped item should get its file generated or not: if it’s inside a `#[doc(hidden)]` item or a private one and not inlined, it shouldn’t get a file.

## Implementations§

Source§

### impl Cache

Source

#### pub(crate) fn new(document_private: bool, document_hidden: bool) -> Self

Source

#### fn parent_stack_last_impl_and_trait_id(&self) -> (Option<DefId>, Option<DefId>)

Source

#### pub(crate) fn populate( cx: &mut DocContext<'_>, krate: Crate, render_options: &RenderOptions, ) -> Crate

Populates the `Cache` with more data. The returned `Crate` will be missing some data that was in `krate` due to the data being moved into the `Cache`.

## Trait Implementations§

Source§

### impl Default for Cache

Source§

#### fn default() -> Cache

Returns the “default value” for a type. Read more

## Auto Trait Implementations§

§

### impl Freeze for Cache

§

### impl RefUnwindSafe for Cache

§

### impl Send for Cache

§

### impl Sync for Cache

§

### impl Unpin for Cache

§

### impl UnsafeUnpin for Cache

§

### impl UnwindSafe for Cache

## 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.

§

### impl<T> Instrument for T

§

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

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

#### 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.
§

### impl<T> WithSubscriber for T

§

#### 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
§

#### 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: 680 bytes