Skip to main content

Crate sourcey_rustdoc

Crate sourcey_rustdoc 

Source
Expand description

Convert nightly rustdoc JSON into a stable RustdocSpec snapshot.

sourcey-rustdoc powers the rustdoc() source adapter in sourcey, the static documentation generator. It is published as a standalone crate so any tool that wants a stable, versioned representation of a Rust crate’s API surface can consume the same schema sourcey uses internally.

§Pipeline

The high-level flow is:

  1. Run nightly rustdoc against a Cargo manifest and capture its JSON output (use the rustdoc-json crate for this step).
  2. Deserialize into rustdoc_types::Crate using a matching rustdoc-types version.
  3. Walk the crate through extract::extract_crate to produce a RustdocSpec tree: modules, items, signature tokens, intra-doc link table, extracted doctests, and resolved external-crate references.
  4. Serialize the spec to JSON for downstream consumers (sourcey’s rustdoc() adapter, alternative renderers, semver-checkers, etc.).

The bundled sourcey-rustdoc binary performs all four steps for the common case. Library callers can drive each step directly.

§Schema stability

SPEC_VERSION is the schema’s major version. Consumers should check RustdocSpec.version on load and bail with a clear remedy when it does not match.

§Examples

use sourcey_rustdoc::{
    extract::{extract_crate, ExtractOptions},
    RustdocSpec, SPEC_VERSION,
};

fn read_snapshot(path: &str) -> serde_json::Result<RustdocSpec> {
    let bytes = std::fs::read(path).expect("snapshot");
    let spec: RustdocSpec = serde_json::from_slice(&bytes)?;
    assert_eq!(spec.version, SPEC_VERSION, "schema version mismatch");
    Ok(spec)
}

Re-exports§

pub use spec::RustdocSpec;
pub use spec::SOURCEY_RUSTDOC_VERSION;
pub use spec::SPEC_VERSION;

Modules§

diagnostics
doctest
extract
links
signature
spec