Printer

Struct Printer 

Source
pub struct Printer<'a> { /* private fields */ }
Expand description

Printer is responsible for generating Markdown documentation from a rustdoc_types::Crate.

It uses a builder pattern for configuration. The typical workflow is:

  1. Create a Printer with Printer::new(&manifest, &krate).
  2. Configure it using builder methods like paths(), crate_extra(), etc.
  3. Call print() to generate the Markdown string.

§Features

  • Path Filtering: Use paths() to specify which items (and their dependencies) should be included in the documentation.
  • README and Examples: Include the crate’s README and examples using crate_extra() with data from CrateExtraReader.
  • “Other” Items: Control the inclusion of items not fitting standard categories with include_other().
  • Template Mode: Generate template markers instead of documentation content using template_mode(), useful for identifying missing documentation.
  • Common Traits Summarization: By default, traits frequently implemented by types are summarized. This can be disabled with no_common_traits().

§Example

For a complete example of using Printer along with other parts of this crate to generate documentation, see the crate-level documentation.

Implementations§

Source§

impl<'a> Printer<'a>

Source

pub fn new(manifest: &'a CargoManifest, krate: &'a Crate) -> Self

Creates a new Printer instance.

§Arguments
Source

pub fn paths(self, paths: &[String]) -> Self

Sets the item path filters for documentation generation.

Items matching these paths (and their dependencies) will be included.

§Path Matching Rules:
  • Paths starting with :: (e.g., ::my_module::MyStruct) are treated as absolute within the current crate.
  • Paths without :: (e.g., my_module::MyStruct or MyStruct) are assumed to be relative to the crate root and will be prefixed with the crate name (e.g., crate_name::my_module::MyStruct).
  • Matches are prefix-based. For example, "::style" will match "::style::TextStyle" and "::style::Color".

If no paths are provided (the default), all items in the crate are considered for selection.

Source

pub fn crate_extra(self, extra: CrateExtra) -> Self

Adds CrateExtra data (README, examples) to be included in the documentation.

Use CrateExtraReader to obtain the CrateExtra instance.

Source

pub fn include_other(self) -> Self

Includes items that don’t fit standard categories in a final “Other” section.

By default, such items (e.g., unprinted selected items that are not modules, impls, or struct fields) are logged as warnings and not included in the output. If this method is called, these items will appear at the end of the documentation, potentially with their source location and dependency graph context.

Source

pub fn template_mode(self) -> Self

Enables template mode for documentation output.

In template mode, instead of the actual documentation content for an item, Mustache-like markers (e.g., {{MISSING_DOCS_1_2_1}}) are inserted. This is useful for identifying where documentation is present or missing in the source crate when generating documentation for LLM training or analysis.

The default is false (template mode disabled).

Source

pub fn no_common_traits(self) -> Self

Disables the “Common Traits” summarization sections.

By default, traits that are frequently implemented by types within the crate or specific modules are summarized in “Common Traits” sections at the crate and module levels. This helps to reduce redundancy in the documentation.

If this method is called, these summary sections are omitted, and all implemented traits for each item will be listed directly with that item’s documentation.

Source

pub fn print(self) -> Result<String>

Generates the Markdown documentation based on the configured options.

This method consumes the Printer and returns the generated Markdown as a String. It performs several steps:

  1. Resolves module items (handling use statements).
  2. Selects items based on path filters and builds a dependency graph.
  3. Calculates common traits for the crate.
  4. Prints the crate header, README (if any), and common traits.
  5. Recursively prints modules and their contents.
  6. Prints any remaining “other” items if configured.
  7. Appends examples if configured.
§Returns

A Result containing the generated Markdown String, or an error if any step fails.

Auto Trait Implementations§

§

impl<'a> Freeze for Printer<'a>

§

impl<'a> RefUnwindSafe for Printer<'a>

§

impl<'a> Send for Printer<'a>

§

impl<'a> Sync for Printer<'a>

§

impl<'a> Unpin for Printer<'a>

§

impl<'a> UnwindSafe for Printer<'a>

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, 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