Skip to content

Add parser-"preview" to all code examples in docs #25967

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

Closed
lukaslueg opened this issue Jun 2, 2015 · 3 comments
Closed

Add parser-"preview" to all code examples in docs #25967

lukaslueg opened this issue Jun 2, 2015 · 3 comments
Labels
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.

Comments

@lukaslueg
Copy link
Contributor

Coming from dynamically typed languages like Python, the docs' code examples tend to provide a repeating dive in the learning curve for me: Rust's syntax is quite complex if you haven't seen much of C++ or similar languages before and most code examples (have to) use syntax features a Rust-beginner has not been introduced to before. Even then, my personal experience was a mix of reading the docs and reading the std's source code to get a hold on how syntax features are used. As a small, probably embarrassing, example, it took me ages for figure out what the 'a in

impl<'a, T: ?Sized, U: ?Sized> AsRef<U> for &'a T where T: AsRef<U> {

stands for...

To remedy the problem, all code examples on docs.rust-lang.org could feature in-place annotations that are automatically generated by passing the code through rust's parser to extract language constructs. Hovering the mouse over blocks, lines, words and characters would cause a javascript-driven tooltip to appear that states what kind of syntax element the mouse cursor is currently hovering over, briefly states what it does and where to find the full documentation on that particular construct.
This would greatly help the already taken assumption that docs are read out of order. It would allow readers to take a brief look or branch off right when they feel comfortable to do so.

As a somewhat more ambitious goal, the annotations could translate the selected code into natural language. As a simple example:

let my_string = String::from("hello");

roughly translates to A [immutable] [variable binding] to 'my_string', taking the return value from the [associated function] 'from' on type ['String']; the implements the [trait] [convert::From]. The parameter "hello" is a [string literal]."

@steveklabnik steveklabnik added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Jun 8, 2015
@steveklabnik
Copy link
Member

This seems, very, very, very hard.

@steveklabnik steveklabnik added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Nov 15, 2016
@steveklabnik
Copy link
Member

Triage: this is kind of a cool idea, but agreeing with my past self, it seems very difficult. If someone wants to write a patch for this, please do, but I don't think I want to keep an issue open tracking it. Thanks!

@durka
Copy link
Contributor

durka commented Dec 1, 2017

explain-rs seems relevant here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

No branches or pull requests

3 participants