Skip to content

Commit

Permalink
better docs
Browse files Browse the repository at this point in the history
  • Loading branch information
aDotInTheVoid committed Jan 22, 2025
1 parent 027f6b0 commit 707ef52
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/rustdoc-json-types/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1038,8 +1038,17 @@ pub enum Type {
pub struct Path {
/// The path of the type.
///
/// This will be the path where the type is *used*, so it may be a
/// re-export.
/// This will be the path that is *used* (not where it is defined), so
/// multiple `Path`s may have different values for this field even if
/// they all refer to the same item. e.g.
///
/// ```rust
/// pub type Vec1 = std::vec::Vec<i32>; // path: "std::vec::Vec"
/// pub type Vec2 = Vec<i32>; // path: "Vec"
/// pub type Vec3 = std::prelude::v1::Vec<i32>; // path: "std::prelude::v1::Vec"
/// ```
//
// Example tested in ./tests/rustdoc-json/path_name.rs
pub path: String,
/// The ID of the type.
pub id: Id,
Expand Down
9 changes: 9 additions & 0 deletions tests/rustdoc-json/path_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,12 @@ pub type Y4 = XPrivMod2;
//@ has "$.paths[*].path" '["defines_and_reexports", "m2", "InPrivMod"]'
//@ !has "$.paths[*].path" '["defines_and_reexports", "InPubMod"]'
//@ !has "$.paths[*].path" '["defines_and_reexports", "InPrivMod"]'

// Tests for the example in the docs of Path::name.
// If these change, chage the docs.
//@ is "$.index[*][?(@.name=='Vec1')].inner.type_alias.type.resolved_path.path" '"std::vec::Vec"'
pub type Vec1 = std::vec::Vec<i32>;
//@ is "$.index[*][?(@.name=='Vec2')].inner.type_alias.type.resolved_path.path" '"Vec"'
pub type Vec2 = Vec<i32>;
//@ is "$.index[*][?(@.name=='Vec3')].inner.type_alias.type.resolved_path.path" '"std::prelude::v1::Vec"'
pub type Vec3 = std::prelude::v1::Vec<i32>;

0 comments on commit 707ef52

Please sign in to comment.