Skip to content

Commit 24db1bb

Browse files
committed
Add doc(hidden) guideline
1 parent 201d903 commit 24db1bb

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/checklist.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
- authors, description, license, homepage, documentation, repository,
3838
readme, keywords, categories
3939
- [ ] Release notes document all significant changes ([C-RELNOTES])
40+
- [ ] Rustdoc does not show unhelpful implementation details ([C-HIDDEN])
4041
- **Predictability** *(crate enables legible code that acts how it looks)*
4142
- [ ] Smart pointers do not add inherent methods ([C-SMART-PTR])
4243
- [ ] Conversions live on the most specific type involved ([C-CONV-SPECIFIC])
@@ -103,6 +104,7 @@
103104
[C-LINK]: documentation.html#c-link
104105
[C-METADATA]: documentation.html#c-metadata
105106
[C-RELNOTES]: documentation.html#c-relnotes
107+
[C-HIDDEN]: documentation.html#c-hidden
106108

107109
[C-SMART-PTR]: predictability.html#c-smart-ptr
108110
[C-CONV-SPECIFIC]: predictability.html#c-conv-specific

src/documentation.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,33 @@ git push --tags
236236
- [Serde 0.9.8 release notes](https://github.com/serde-rs/serde/releases/tag/v0.9.8)
237237
- [Serde 0.9.0 release notes](https://github.com/serde-rs/serde/releases/tag/v0.9.0)
238238
- [Diesel change log](https://github.com/diesel-rs/diesel/blob/master/CHANGELOG.md)
239+
240+
241+
<a id="c-hidden"></a>
242+
## Rustdoc does not show unhelpful implementation details (C-HIDDEN)
243+
244+
Rustdoc is supposed to include everything users need to use the crate fully and
245+
nothing more. It is fine to explain relevant implementation details in prose but
246+
they should not be real entries in the documentation.
247+
248+
Especially be selective about which impls are visible in rustdoc -- all the ones
249+
that users would need for using the crate fully, but no others. In the following
250+
code the rustdoc of `PublicError` by default would show the `From<PrivateError>`
251+
impl. We choose to hide it with `#[doc(hidden)]` because users can never have a
252+
`PrivateError` in their code so this impl would never be relevant to them.
253+
254+
```rust
255+
// This error type is returned to users.
256+
pub struct PublicError { /* ... */ }
257+
258+
// This error type is returned by some private helper functions.
259+
struct PrivateError { /* ... */ }
260+
261+
// Enable use of `?` operator.
262+
#[doc(hidden)]
263+
impl From<PrivateError> for PublicError {
264+
fn from(err: PrivateError) -> PublicError {
265+
/* ... */
266+
}
267+
}
268+
```

0 commit comments

Comments
 (0)