diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5bfe31c..f86403f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,12 @@
+
+# [v0.28.1](https://github.com/aDotInTheVoid/rustdoc-types/releases/tag/v0.28.1) - 2024-08-01
+
+**Documentation Improvements**: The libray is now (almost) entirely documented ([rust#127290](https://github.com/rust-lang/rust/pull/127290))!
+
+- Format Version: 32
+- Upstream Commit: [`47b76d8d939be6085e9b1f6fc1a4b959346754a6`](https://github.com/rust-lang/rust/commit/47b76d8d939be6085e9b1f6fc1a4b959346754a6)
+- Diff: [v0.28.0...v0.28.1](https://github.com/aDotInTheVoid/rustdoc-types/compare/v0.28.0...v0.28.1)
+
# [v0.28.0](https://github.com/aDotInTheVoid/rustdoc-types/releases/tag/v0.28.0) - 2024-07-18
diff --git a/COMMIT.txt b/COMMIT.txt
index 6675757..d33bcc3 100644
--- a/COMMIT.txt
+++ b/COMMIT.txt
@@ -1 +1 @@
-bd135e487f904e757f6c3d2ebcc2d216ac4d9aaf
+47b76d8d939be6085e9b1f6fc1a4b959346754a6
diff --git a/Cargo.toml b/Cargo.toml
index a4fc7d1..5d8bd52 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "rustdoc-types"
-version = "0.28.0"
+version = "0.28.1"
edition = "2018"
license = "MIT OR Apache-2.0"
description = "Types for rustdoc's json output"
diff --git a/src/lib.rs b/src/lib.rs
index 3e9238c..041e007 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -3,14 +3,21 @@
//! These types are the public API exposed through the `--output-format json` flag. The [`Crate`]
//! struct is the root of the JSON blob and all other items are contained within.
+use std::path::PathBuf;
+
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
-use std::path::PathBuf;
-/// rustdoc format-version.
+/// The version of JSON output that this crate represents.
+///
+/// This integer is incremented with every breaking change to the API,
+/// and is returned along with the JSON blob as [`Crate::format_version`].
+/// Consuming code should assert that this value matches the format version(s) that it supports.
pub const FORMAT_VERSION: u32 = 32;
-/// A `Crate` is the root of the emitted JSON blob. It contains all type/documentation information
+/// The root of the emitted JSON blob.
+///
+/// It contains all type/documentation information
/// about the language items in the local crate, as well as info about external items to allow
/// tools to find or link to them.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
@@ -33,13 +40,18 @@ pub struct Crate {
pub format_version: u32,
}
+/// Metadata of a crate, either the same crate on which `rustdoc` was invoked, or its dependency.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct ExternalCrate {
+ /// The name of the crate.
pub name: String,
+ /// The root URL at which the crate's documentation lives.
pub html_root_url: Option,
}
-/// For external (not defined in the local crate) items, you don't get the same level of
+/// Information about an external (not defined in the local crate) [`Item`].
+///
+/// For external items, you don't get the same level of
/// information. This struct should contain enough to generate a link/reference to the item in
/// question, or can be used by a tool that takes the json output of multiple crates to find
/// the actual item definition with all the relevant info.
@@ -60,6 +72,10 @@ pub struct ItemSummary {
pub kind: ItemKind,
}
+/// Anything that can hold documentation - modules, structs, enums, functions, traits, etc.
+///
+/// The `Item` data type holds fields that can apply to any of these,
+/// and leaves kind-specific details (like function args or enum variants) to the `inner` field.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Item {
/// The unique identifier of this item. Can be used to find this item in various mappings.
@@ -82,10 +98,13 @@ pub struct Item {
pub links: HashMap,
/// Stringified versions of the attributes on this item (e.g. `"#[inline]"`)
pub attrs: Vec,
+ /// Information about the item’s deprecation, if present.
pub deprecation: Option,
+ /// The type-specific fields describing this item.
pub inner: ItemEnum,
}
+/// A range of source code.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Span {
/// The path to the source file for this span relative to the path `rustdoc` was invoked with.
@@ -96,28 +115,39 @@ pub struct Span {
pub end: (usize, usize),
}
+/// Information about the deprecation of an [`Item`].
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Deprecation {
+ /// Usually a version number when this [`Item`] first became deprecated.
pub since: Option,
+ /// The reason for deprecation and/or what alternatives to use.
pub note: Option,
}
+/// Visibility of an [`Item`].
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Visibility {
+ /// Explicitly public visibility set with `pub`.
Public,
/// For the most part items are private by default. The exceptions are associated items of
/// public traits and variants of public enums.
Default,
+ /// Explicitly crate-wide visibility set with `pub(crate)`
Crate,
- /// For `pub(in path)` visibility. `parent` is the module it's restricted to and `path` is how
- /// that module was referenced (like `"super::super"` or `"crate::foo::bar"`).
+ /// For `pub(in path)` visibility.
Restricted {
+ /// ID of the module to which this visibility restricts items.
parent: Id,
+ /// The path with which [`parent`] was referenced
+ /// (like `super::super` or `crate::foo::bar`).
+ ///
+ /// [`parent`]: Visibility::Restricted::parent
path: String,
},
}
+/// Dynamic trait object type (`dyn Trait`).
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct DynTrait {
/// All the traits implemented. One of them is the vtable, and the rest must be auto traits.
@@ -132,64 +162,133 @@ pub struct DynTrait {
pub lifetime: Option,
}
-#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
/// A trait and potential HRTBs
+#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct PolyTrait {
+ /// The path to the trait.
#[serde(rename = "trait")]
pub trait_: Path,
/// Used for Higher-Rank Trait Bounds (HRTBs)
/// ```text
/// dyn for<'a> Fn() -> &'a i32"
/// ^^^^^^^
- /// |
- /// this part
/// ```
pub generic_params: Vec,
}
+/// A set of generic arguments provided to a path segment, e.g.
+///
+/// ```text
+/// std::option::Option::::None
+/// ^^^^^
+/// ```
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum GenericArgs {
- /// <'a, 32, B: Copy, C = u32>
- AngleBracketed { args: Vec, bindings: Vec },
- /// Fn(A, B) -> C
- Parenthesized { inputs: Vec, output: Option },
+ /// `<'a, 32, B: Copy, C = u32>`
+ AngleBracketed {
+ /// The list of each argument on this type.
+ /// ```text
+ /// <'a, 32, B: Copy, C = u32>
+ /// ^^^^^^
+ /// ```
+ args: Vec,
+ /// Associated type or constant bindings (e.g. `Item=i32` or `Item: Clone`) for this type.
+ bindings: Vec,
+ },
+ /// `Fn(A, B) -> C`
+ Parenthesized {
+ /// The input types, enclosed in parentheses.
+ inputs: Vec,
+ /// The output type provided after the `->`, if present.
+ output: Option,
+ },
}
+/// One argument in a list of generic arguments to a path segment.
+///
+/// Part of [`GenericArgs`].
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum GenericArg {
+ /// A lifetime argument.
+ /// ```text
+ /// std::borrow::Cow<'static, str>
+ /// ^^^^^^^
+ /// ```
Lifetime(String),
+ /// A type argument.
+ /// ```text
+ /// std::borrow::Cow<'static, str>
+ /// ^^^
+ /// ```
Type(Type),
+ /// A constant as a generic argument.
+ /// ```text
+ /// core::array::IntoIter
+ /// ^^^^^^^^^^^^^^
+ /// ```
Const(Constant),
+ /// A generic argument that's explicitly set to be inferred.
+ /// ```text
+ /// std::vec::Vec::<_>::new()
+ /// ^
+ /// ```
Infer,
}
+/// A constant.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Constant {
+ /// The stringified expression of this constant. Note that its mapping to the original
+ /// source code is unstable and it's not guaranteed that it'll match the source code.
pub expr: String,
+ /// The value of the evaluated expression for this constant, which is only computed for numeric
+ /// types.
pub value: Option,
+ /// Whether this constant is a bool, numeric, string, or char literal.
pub is_literal: bool,
}
+/// Describes a bound applied to an associated type/constant.
+///
+/// Example:
+/// ```text
+/// IntoIterator
+/// ^^^^^^^^^^ ^^^^^^^^^^^^^^^
+/// ```
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct TypeBinding {
+ /// The name of the associated type/constant.
pub name: String,
+ /// Arguments provided to the associated type/constant.
pub args: GenericArgs,
+ /// The kind of bound applied to the associated type/constant.
pub binding: TypeBindingKind,
}
+/// The way in which an associate type/constant is bound.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum TypeBindingKind {
+ /// The required value/type is specified exactly. e.g.
+ /// ```text
+ /// Iterator
+ /// ^^^^^^^^^^
+ /// ```
Equality(Term),
+ /// The type is required to satisfy a set of bounds.
+ /// ```text
+ /// Iterator
+ /// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ /// ```
Constraint(Vec),
}
/// An opaque identifier for an item.
///
-/// It can be used to lookup in [Crate::index] or [Crate::paths] to resolve it
-/// to an [Item].
+/// It can be used to lookup in [`Crate::index`] or [`Crate::paths`] to resolve it
+/// to an [`Item`].
///
/// Id's are only valid within a single JSON blob. They cannot be used to
/// resolve references between the JSON output's for different crates.
@@ -201,115 +300,230 @@ pub enum TypeBindingKind {
// FIXME(aDotInTheVoid): Consider making this non-public in rustdoc-types.
pub struct Id(pub String);
+/// The fundamental kind of an item. Unlike [`ItemEnum`], this does not carry any aditional info.
+///
+/// Part of [`ItemSummary`].
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ItemKind {
+ /// A module declaration, e.g. `mod foo;` or `mod foo {}`
Module,
+ /// A crate imported via the `extern crate` syntax.
ExternCrate,
+ /// An import of 1 or more items into scope, using the `use` keyword.
Import,
+ /// A `struct` declaration.
Struct,
+ /// A field of a struct.
StructField,
+ /// A `union` declaration.
Union,
+ /// An `enum` declaration.
Enum,
+ /// A variant of a enum.
Variant,
+ /// A function declaration, e.g. `fn f() {}`
Function,
+ /// A type alias declaration, e.g. `type Pig = std::borrow::Cow<'static, str>;`
TypeAlias,
OpaqueTy,
+ /// The declaration of a constant, e.g. `const GREETING: &str = "Hi :3";`
Constant,
+ /// A `trait` declaration.
Trait,
+ /// A trait alias declaration, e.g. `trait Int = Add + Sub + Mul + Div;`
+ ///
+ /// See [the tracking issue](https://github.com/rust-lang/rust/issues/41517)
TraitAlias,
+ /// An `impl` block.
Impl,
+ /// A `static` declaration.
Static,
+ /// `type`s from an `extern` block.
+ ///
+ /// See [the tracking issue](https://github.com/rust-lang/rust/issues/43467)
ForeignType,
+ /// A macro declaration.
+ ///
+ /// Corresponds to either `ItemEnum::Macro(_)`
+ /// or `ItemEnum::ProcMacro(ProcMacro { kind: MacroKind::Bang })`
Macro,
+ /// A procedural macro attribute.
+ ///
+ /// Corresponds to `ItemEnum::ProcMacro(ProcMacro { kind: MacroKind::Attr })`
ProcAttribute,
+ /// A procedural macro usable in the `#[derive()]` attribute.
+ ///
+ /// Corresponds to `ItemEnum::ProcMacro(ProcMacro { kind: MacroKind::Derive })`
ProcDerive,
+ /// An associated constant of a trait or a type.
AssocConst,
+ /// An associated type of a trait or a type.
AssocType,
+ /// A primitive type, e.g. `u32`.
+ ///
+ /// [`Item`]s of this kind only come from the core library.
Primitive,
+ /// A keyword declaration.
+ ///
+ /// [`Item`]s of this kind only come from the come library and exist solely
+ /// to carry documentation for the respective keywords.
Keyword,
}
+/// Specific fields of an item.
+///
+/// Part of [`Item`].
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ItemEnum {
+ /// A module declaration, e.g. `mod foo;` or `mod foo {}`
Module(Module),
+ /// A crate imported via the `extern crate` syntax.
ExternCrate {
+ /// The name of the imported crate.
name: String,
+ /// If the crate is renamed, this is its name in the crate.
rename: Option,
},
+ /// An import of 1 or more items into scope, using the `use` keyword.
Import(Import),
+ /// A `union` declaration.
Union(Union),
+ /// A `struct` declaration.
Struct(Struct),
+ /// A field of a struct.
StructField(Type),
+ /// An `enum` declaration.
Enum(Enum),
+ /// A variant of a enum.
Variant(Variant),
+ /// A function declaration (including methods and other associated functions)
Function(Function),
+ /// A `trait` declaration.
Trait(Trait),
+ /// A trait alias declaration, e.g. `trait Int = Add + Sub + Mul + Div;`
+ ///
+ /// See [the tracking issue](https://github.com/rust-lang/rust/issues/41517)
TraitAlias(TraitAlias),
+ /// An `impl` block.
Impl(Impl),
+ /// A type alias declaration, e.g. `type Pig = std::borrow::Cow<'static, str>;`
TypeAlias(TypeAlias),
OpaqueTy(OpaqueTy),
+ /// The declaration of a constant, e.g. `const GREETING: &str = "Hi :3";`
Constant {
+ /// The type of the constant.
#[serde(rename = "type")]
type_: Type,
+ /// The declared constant itself.
#[serde(rename = "const")]
const_: Constant,
},
+ /// A declaration of a `static`.
Static(Static),
- /// `type`s from an extern block
+ /// `type`s from an `extern` block.
+ ///
+ /// See [the tracking issue](https://github.com/rust-lang/rust/issues/43467)
ForeignType,
- /// Declarative macro_rules! macro
+ /// A macro_rules! declarative macro. Contains a single string with the source
+ /// representation of the macro with the patterns stripped.
Macro(String),
+ /// A procedural macro.
ProcMacro(ProcMacro),
+ /// A primitive type, e.g. `u32`.
+ ///
+ /// [`Item`]s of this kind only come from the core library.
Primitive(Primitive),
+ /// An associated constant of a trait or a type.
AssocConst {
+ /// The type of the constant.
#[serde(rename = "type")]
type_: Type,
- /// e.g. `const X: usize = 5;`
+ /// The stringified expression for the default value, if provided, e.g.
+ /// ```rust
+ /// const X: usize = 640 * 1024;
+ /// // ^^^^^^^^^^
+ /// ```
default: Option,
},
+ /// An associated type of a trait or a type.
AssocType {
+ /// The generic parameters and where clauses on ahis associated type.
generics: Generics,
+ /// The bounds for this associated type. e.g.
+ /// ```rust
+ /// trait IntoIterator {
+ /// type Item;
+ /// type IntoIter: Iterator;
+ /// // ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ /// }
+ /// ```
bounds: Vec,
- /// e.g. `type X = usize;`
+ /// The default for this type, if provided, e.g.
+ /// ```rust
+ /// type X = usize;
+ /// // ^^^^^
+ /// ```
default: Option,
},
}
+/// A module declaration, e.g. `mod foo;` or `mod foo {}`.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Module {
+ /// Whether this is the root item of a crate.
+ ///
+ /// This item doesn't correspond to any construction in the source code and is generated by the
+ /// compiler.
pub is_crate: bool,
+ /// [`Item`]s declared inside this module.
pub items: Vec,
/// If `true`, this module is not part of the public API, but it contains
/// items that are re-exported as public API.
pub is_stripped: bool,
}
+/// A `union`.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Union {
+ /// The generic parameters and where clauses on this union.
pub generics: Generics,
+ /// Whether any fields have been removed from the result, due to being private or hidden.
pub fields_stripped: bool,
+ /// The list of fields in the union.
+ ///
+ /// All of the corresponding [`Item`]s are of kind [`ItemEnum::StructField`].
pub fields: Vec,
+ /// All impls (both of traits and inherent) for this union.
+ ///
+ /// All of the corresponding [`Item`]s are of kind [`ItemEnum::Impl`].
pub impls: Vec,
}
+/// A `struct`.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Struct {
+ /// The kind of the struct (e.g. unit, tuple-like or struct-like) and the data specific to it,
+ /// i.e. fields.
pub kind: StructKind,
+ /// The generic parameters and where clauses on this struct.
pub generics: Generics,
+ /// All impls (both of traits and inherent) for this struct.
+ /// All of the corresponding [`Item`]s are of kind [`ItemEnum::Impl`].
pub impls: Vec,
}
+/// The kind of a [`Struct`] and the data specific to it, i.e. fields.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum StructKind {
@@ -321,13 +535,14 @@ pub enum StructKind {
Unit,
/// A struct with unnamed fields.
///
+ /// All [`Id`]'s will point to [`ItemEnum::StructField`].
+ /// Unlike most of JSON, private and `#[doc(hidden)]` fields will be given as `None`
+ /// instead of being omitted, because order matters.
+ ///
/// ```rust
/// pub struct TupleStruct(i32);
/// pub struct EmptyTupleStruct();
/// ```
- ///
- /// All [`Id`]'s will point to [`ItemEnum::StructField`]. Private and
- /// `#[doc(hidden)]` fields will be given as `None`
Tuple(Vec