Add parser-"preview" to all code examples in docs #25967
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.
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
instands 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:
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]."
The text was updated successfully, but these errors were encountered: