Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo doc should render crate examples and link to them on main documentation page #133348

Open
burtonageo opened this issue Jun 1, 2016 · 5 comments
Labels
A-rustdoc-scrape-examples Area: The (unstable) rustdoc scrape-examples feature described in RFC 3123 A-rustdoc-ui Area: Rustdoc UI (generated HTML) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Comments

@burtonageo
Copy link
Contributor

(re-filing of #34022)

Cargo allows crate developers to create examples to show off their crate's API (as shown in http://doc.crates.io/guide.html#project-layout). These examples are very useful to see how the individual items in a crate can be used together, in a way that the standard documentation doesn't capture very well.

When viewing a crate's documentation, it would be useful if examples were rendered as standard source files, and there were links to view them on the main library overview page.

@burtonageo burtonageo changed the title [rustdoc] Rustdoc should render crate examples and link to them on main documentation page cargo doc should render crate examples and link to them on main documentation page Jun 1, 2016
@japaric
Copy link
Member

japaric commented Oct 6, 2016

I have a shell script that I'm using in my f3 crate to do something like this but I'd really like to see something official implemented in Cargo and rustdoc.

For the interested: In my crate, this is a typical input example (examples/panic.rs); the scripts turns it into another .rs file and places it into the examples module (src/examples/panic.rs); and this is how the rendered output looks like.

@Dragonrun1
Copy link

So thought I'd bump this issue and see if there anyone looking at adding this IMHO very helpful feature.

@epage
Copy link
Contributor

epage commented Apr 21, 2022

#88791 scrapes the examples and links to them from the API items used in the examples but it doesn't seem to provide a central list of all examples. @willcrichton did that idea ever come up?

@willcrichton
Copy link
Contributor

We haven't talked about exactly that concept, but it's a great idea! FWIW, as a part of my scrape examples feature, rustdoc will now generate source files for scraped examples. So that infrastructure could be reused for this proposed feature.

One challenge to consider: a number of crates have examples, but these examples don't fall under the --examples filter. For instance, the gtk3-rs crate requires you to run examples via --bin. I think this is because Cargo doesn't allow examples to have standalone Cargo.toml configurations, but gtk3-rs needs that ability. So the simple implementation of this feature being "list out every file that matches the --examples filter" would not work for some crates.

The broader point: it might make sense for this feature to go hand-in-hand with a broader push to improve the examples directory. It's been kind of a second-class citizen of Cargo for a while.

@epage epage added the S-triage label Sep 28, 2023
@epage
Copy link
Contributor

epage commented Nov 22, 2024

While originally examples were only a Cargo concept, with example-scraping, they are now a rustdoc concept. As this is about improving their rendering, I'm going to move this back to the rust repo.

Improving the handling of examples with their own Cargo.toml would need to be tracked as its own thing.

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 22, 2024
@epage epage transferred this issue from rust-lang/cargo Nov 22, 2024
@jieyouxu jieyouxu added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. C-enhancement Category: An issue proposing an enhancement or a PR with one. A-rustdoc-ui Area: Rustdoc UI (generated HTML) A-rustdoc-scrape-examples Area: The (unstable) rustdoc scrape-examples feature described in RFC 3123 and removed S-triage needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-scrape-examples Area: The (unstable) rustdoc scrape-examples feature described in RFC 3123 A-rustdoc-ui Area: Rustdoc UI (generated HTML) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.
Projects
None yet
Development

No branches or pull requests

7 participants