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:
- Run nightly rustdoc against a Cargo manifest and capture its JSON
output (use the
rustdoc-jsoncrate for this step). - Deserialize into
rustdoc_types::Crateusing a matchingrustdoc-typesversion. - Walk the crate through
extract::extract_crateto produce aRustdocSpectree: modules, items, signature tokens, intra-doc link table, extracted doctests, and resolved external-crate references. - 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;