- 
                Notifications
    
You must be signed in to change notification settings  - Fork 1.5k
 
feat: add doc attributes section to documentation #1323
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
          
     Merged
      
      
            marioidival
  merged 7 commits into
  rust-lang:master
from
jsjoeio:jsjoeio/108-doc-attribute-examples
  
      
      
   
  Mar 30, 2020 
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            7 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      6a0cdb0
              
                feat: add doc attributes section to documentation
              
              
                 94ca1f7
              
                Update src/meta/doc.md
              
              
                jsjoeio d72084b
              
                Merge branch 'master' into jsjoeio/108-doc-attribute-examples
              
              
                jsjoeio 4324f2e
              
                feat: add doc attributes section to documentation
              
              
                 26b30d3
              
                Merge branch 'jsjoeio/108-doc-attribute-examples' of https://github.c…
              
              
                jsjoeio 051382a
              
                fix: ignore code examples in doc
              
              
                jsjoeio 5382d4b
              
                feat: add example with ignore to playpen
              
              
                jsjoeio File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -6,13 +6,13 @@ Use `cargo test` to run all tests (including documentation tests), and `cargo te | |
| 
     | 
||
| These commands will appropriately invoke `rustdoc` (and `rustc`) as required. | ||
| 
     | 
||
| ### Doc comments | ||
| ## Doc comments | ||
| 
     | 
||
| Doc comments are very useful for big projects that require documentation. When | ||
| running `rustdoc`, these are the comments that get compiled into | ||
| documentation. They are denoted by a `///`, and support [Markdown]. | ||
| 
     | 
||
| ```rust,editable,ignore | ||
| ````rust,editable,ignore | ||
| #![crate_name = "doc"] | ||
| 
     | 
||
| /// A human being is represented here | ||
| 
          
            
          
           | 
    @@ -55,7 +55,7 @@ fn main() { | |
| 
     | 
||
| john.hello(); | ||
| } | ||
| ``` | ||
| ```` | ||
| 
     | 
||
| To run the tests, first build the code as a library, then tell `rustdoc` where | ||
| to find the library so it can link it into each doctest program: | ||
| 
        
          
        
         | 
    @@ -65,18 +65,57 @@ $ rustc doc.rs --crate-type lib | |
| $ rustdoc --test --extern doc="libdoc.rlib" doc.rs | ||
| ``` | ||
| 
     | 
||
| ## Doc attributes | ||
| 
     | 
||
| Below are a few examples of the most common `#[doc]` attributes used with `rustdoc`. | ||
| 
     | 
||
| ### `inline` | ||
| 
     | 
||
| Used to inline docs, instead of linking out to separate page. | ||
| 
     | 
||
| ```rust,ignore | ||
| #[doc(inline)] | ||
| pub use bar::Bar; | ||
| 
     | 
||
| /// bar docs | ||
| mod bar { | ||
| /// the docs for Bar | ||
| pub struct Bar; | ||
| } | ||
| ``` | ||
| 
     | 
||
| ### `no_inline` | ||
| 
     | 
||
| Used to prevent linking out to separate page or anywhere. | ||
| 
     | 
||
| ```rust,ignore | ||
| // Example from libcore/prelude | ||
| #[doc(no_inline)] | ||
| pub use crate::mem::drop; | ||
| ``` | ||
| 
     | 
||
| ### `hidden` | ||
| 
         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. These are all covered more deeply in the   | 
||
| 
     | 
||
| Using this tells `rustdoc` not to include this in documentation: | ||
| 
     | 
||
| ```rust,editable,ignore | ||
| // Example from the futures-rs library | ||
| #[doc(hidden)] | ||
| pub use self::async_await::*; | ||
| ``` | ||
| 
     | 
||
| For documentation, `rustdoc` is widely used by the community. It's what is used to generate the [std library docs](https://doc.rust-lang.org/std/). | ||
| 
     | 
||
| ### See also: | ||
| 
     | 
||
| * [The Rust Book: Making Useful Documentation Comments][book] | ||
| * [The rustdoc Book][rustdoc-book] | ||
| * [The Reference: Doc comments][ref-comments] | ||
| * [RFC 1574: API Documentation Conventions][api-conv] | ||
| * [RFC 1946: Relative links to other items from doc comments (intra-rustdoc links)][intra-links] | ||
| * [Is there any documentation style guide for comments? (reddit)][reddit] | ||
| - [The Rust Book: Making Useful Documentation Comments][book] | ||
| - [The rustdoc Book][rustdoc-book] | ||
| - [The Reference: Doc comments][ref-comments] | ||
| - [RFC 1574: API Documentation Conventions][api-conv] | ||
| - [RFC 1946: Relative links to other items from doc comments (intra-rustdoc links)][intra-links] | ||
| - [Is there any documentation style guide for comments? (reddit)][reddit] | ||
| 
     | 
||
| [Markdown]: https://en.wikipedia.org/wiki/Markdown | ||
| [markdown]: https://en.wikipedia.org/wiki/Markdown | ||
| [book]: https://doc.rust-lang.org/book/ch14-02-publishing-to-crates-io.html#making-useful-documentation-comments | ||
| [ref-comments]: https://doc.rust-lang.org/stable/reference/comments.html#doc-comments | ||
| [rustdoc-book]: https://doc.rust-lang.org/rustdoc/index.html | ||
| 
          
            
          
           | 
    ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.