-
Notifications
You must be signed in to change notification settings - Fork 14k
Reintroduce spotlight/"important traits" feature #74111
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # `doc_spotlight` | ||
|
|
||
| The tracking issue for this feature is: [#45040] | ||
|
|
||
| The `doc_spotlight` feature allows the use of the `spotlight` parameter to the `#[doc]` attribute, | ||
| to "spotlight" a specific trait on the return values of functions. Adding a `#[doc(spotlight)]` | ||
| attribute to a trait definition will make rustdoc print extra information for functions which return | ||
| a type that implements that trait. This attribute is applied to the `Iterator`, `io::Read`, and | ||
| `io::Write` traits in the standard library. | ||
|
|
||
| You can do this on your own traits, like this: | ||
|
|
||
| ``` | ||
| #![feature(doc_spotlight)] | ||
|
|
||
| #[doc(spotlight)] | ||
| pub trait MyTrait {} | ||
|
|
||
| pub struct MyStruct; | ||
| impl MyTrait for MyStruct {} | ||
|
|
||
| /// The docs for this function will have an extra line about `MyStruct` implementing `MyTrait`, | ||
| /// without having to write that yourself! | ||
| pub fn my_fn() -> MyStruct { MyStruct } | ||
| ``` | ||
|
|
||
| This feature was originally implemented in PR [#45039]. | ||
|
|
||
| [#45040]: https://github.com/rust-lang/rust/issues/45040 | ||
| [#45039]: https://github.com/rust-lang/rust/pull/45039 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -363,6 +363,7 @@ function defocusSearchBar() { | |
| function handleEscape(ev) { | ||
| var help = getHelpElement(); | ||
| var search = getSearchElement(); | ||
| hideModal(); | ||
| if (hasClass(help, "hidden") === false) { | ||
| displayHelp(false, ev, help); | ||
| } else if (hasClass(search, "hidden") === false) { | ||
|
|
@@ -395,6 +396,7 @@ function defocusSearchBar() { | |
| case "s": | ||
| case "S": | ||
| displayHelp(false, ev); | ||
| hideModal(); | ||
| ev.preventDefault(); | ||
| focusSearchBar(); | ||
| break; | ||
|
|
@@ -407,6 +409,7 @@ function defocusSearchBar() { | |
|
|
||
| case "?": | ||
| if (ev.shiftKey) { | ||
| hideModal(); | ||
| displayHelp(true, ev); | ||
| } | ||
| break; | ||
|
|
@@ -2621,6 +2624,16 @@ function defocusSearchBar() { | |
| }); | ||
| }()); | ||
|
|
||
| function showImportantTraits(content) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, this function is never used. Please remove it. |
||
| let list = content.classList | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing |
||
| } | ||
|
|
||
| onEachLazy(document.getElementsByClassName("important-traits"), function(e) { | ||
| e.onclick = function() { | ||
| e.getElementsByClassName('important-traits-tooltiptext')[0].classList.toggle("force-tooltip") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's better to use either
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't that just be
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not too confident about the variable capture process in JS so I prefer to minimize it as much as possible.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also missing |
||
| }; | ||
| }); | ||
|
|
||
| // In the search display, allows to switch between tabs. | ||
| function printTab(nb) { | ||
| if (nb === 0 || nb === 1 || nb === 2) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you add the
hideModalcalls BTW?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't intend to. Will fix.