Sophie

Sophie

distrib > Mageia > 6 > armv7hl > media > core-updates > by-pkgid > 4e2dbb669434a7691662cb2f0ad38972 > files > 11494

rust-doc-1.28.0-1.mga6.armv7hl.rpm

<!DOCTYPE HTML>
<html lang="en" class="sidebar-visible no-js">
    <head>
        <!-- Book generated using mdBook -->
        <meta charset="UTF-8">
        <title>The #[doc] attribute - </title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="theme-color" content="#ffffff" />

        <base href="">

        <link rel="stylesheet" href="book.css">
        <link href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel="stylesheet" type="text/css">
        <link href="https://fonts.googleapis.com/css?family=Source+Code+Pro:500" rel="stylesheet" type="text/css">

        <link rel="shortcut icon" href="favicon.png">

        <!-- Font Awesome -->
        <link rel="stylesheet" href="_FontAwesome/css/font-awesome.css">

        <link rel="stylesheet" href="highlight.css">
        <link rel="stylesheet" href="tomorrow-night.css">
        <link rel="stylesheet" href="ayu-highlight.css">

        <!-- Custom theme stylesheets -->
        

        

    </head>
    <body class="light">
        <!-- Work around some values being stored in localStorage wrapped in quotes -->
        <script type="text/javascript">
            try {
                var theme = localStorage.getItem('mdbook-theme');
                var sidebar = localStorage.getItem('mdbook-sidebar');

                if (theme.startsWith('"') && theme.endsWith('"')) {
                    localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
                }

                if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
                    localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
                }
            } catch (e) { }
        </script>

        <!-- Set the theme before any content is loaded, prevents flash -->
        <script type="text/javascript">
            var theme;
            try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { } 
            if (theme === null || theme === undefined) { theme = 'light'; }
            document.body.className = theme;
            document.querySelector('html').className = theme + ' js';
        </script>

        <!-- Hide / unhide sidebar before it is displayed -->
        <script type="text/javascript">
            var html = document.querySelector('html');
            var sidebar = 'hidden';
            if (document.body.clientWidth >= 1080) {
                try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
                sidebar = sidebar || 'visible';
            }
            html.classList.remove('sidebar-visible');
            html.classList.add("sidebar-" + sidebar);
        </script>

        <nav id="sidebar" class="sidebar" aria-label="Table of contents">
            <ol class="chapter"><li><a href="what-is-rustdoc.html"><strong aria-hidden="true">1.</strong> What is rustdoc?</a></li><li><a href="command-line-arguments.html"><strong aria-hidden="true">2.</strong> Command-line arguments</a></li><li><a href="the-doc-attribute.html" class="active"><strong aria-hidden="true">3.</strong> The #[doc] attribute</a></li><li><a href="documentation-tests.html"><strong aria-hidden="true">4.</strong> Documentation tests</a></li><li><a href="passes.html"><strong aria-hidden="true">5.</strong> Passes</a></li><li><a href="unstable-features.html"><strong aria-hidden="true">6.</strong> Unstable features</a></li></ol>
        </nav>

        <div id="page-wrapper" class="page-wrapper">

            <div class="page">
                
                <div id="menu-bar" class="menu-bar">
                    <div id="menu-bar-sticky-container">
                        <div class="left-buttons">
                            <button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
                                <i class="fa fa-bars"></i>
                            </button>
                            <button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
                                <i class="fa fa-paint-brush"></i>
                            </button>
                            <ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
                                <li role="none"><button role="menuitem" class="theme" id="light">Light <span class="default">(default)</span></button></li>
                                <li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
                                <li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
                                <li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
                                <li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
                            </ul>
                            
                            <button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
                                <i class="fa fa-search"></i>
                            </button>
                            
                        </div>

                        <h1 class="menu-title"></h1> 

                        <div class="right-buttons">
                            <a href="print.html" title="Print this book" aria-label="Print this book">
                                <i id="print-button" class="fa fa-print"></i>
                            </a>
                        </div>
                    </div>
                </div>

                
                <div id="search-wrapper" class="hidden">
                    <form id="searchbar-outer" class="searchbar-outer">
                        <input type="search" name="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
                    </form>
                    <div id="searchresults-outer" class="searchresults-outer hidden">
                        <div id="searchresults-header" class="searchresults-header"></div>
                        <ul id="searchresults">
                        </ul>
                    </div>
                </div>
                

                <!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
                <script type="text/javascript">
                    document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
                    document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
                    Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
                        link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
                    });
                </script>

                <div id="content" class="content">
                    <main>
                        <a class="header" href="the-doc-attribute.html#the-doc-attribute" id="the-doc-attribute"><h1>The <code>#[doc]</code> attribute</h1></a>
<p>The <code>#[doc]</code> attribute lets you control various aspects of how <code>rustdoc</code> does
its job.</p>
<p>The most basic function of <code>#[doc]</code> is to handle the actual documentation
text. That is, <code>///</code> is syntax sugar for <code>#[doc]</code>. This means that these two
are the same:</p>
<pre><code class="language-rust ignore">/// This is a doc comment.
#[doc = &quot; This is a doc comment.&quot;]
</code></pre>
<p>(Note the leading space in the attribute version.)</p>
<p>In most cases, <code>///</code> is easier to use than <code>#[doc]</code>. One case where the latter is easier is
when generating documentation in macros; the <code>collapse-docs</code> pass will combine multiple
<code>#[doc]</code> attributes into a single doc comment, letting you generate code like this:</p>
<pre><code class="language-rust ignore">#[doc = &quot;This is&quot;]
#[doc = &quot; a &quot;]
#[doc = &quot;doc comment&quot;]
</code></pre>
<p>Which can feel more flexible. Note that this would generate this:</p>
<pre><code class="language-rust ignore">#[doc = &quot;This is\n a \ndoc comment&quot;]
</code></pre>
<p>but given that docs are rendered via Markdown, it will remove these newlines.</p>
<p>The <code>doc</code> attribute has more options though! These don't involve the text of
the output, but instead, various aspects of the presentation of the output.
We've split them into two kinds below: attributes that are useful at the
crate level, and ones that are useful at the item level.</p>
<a class="header" href="the-doc-attribute.html#at-the-crate-level" id="at-the-crate-level"><h2>At the crate level</h2></a>
<p>These options control how the docs look at a macro level.</p>
<a class="header" href="the-doc-attribute.html#html_favicon_url" id="html_favicon_url"><h3><code>html_favicon_url</code></h3></a>
<p>This form of the <code>doc</code> attribute lets you control the favicon of your docs.</p>
<pre><code class="language-rust ignore">#![doc(html_favicon_url = &quot;https://example.com/favicon.ico&quot;)]
</code></pre>
<p>This will put <code>&lt;link rel=&quot;shortcut icon&quot; href=&quot;{}&quot;&gt;</code> into your docs, where
the string for the attribute goes into the <code>{}</code>.</p>
<p>If you don't use this attribute, there will be no favicon.</p>
<a class="header" href="the-doc-attribute.html#html_logo_url" id="html_logo_url"><h3><code>html_logo_url</code></h3></a>
<p>This form of the <code>doc</code> attribute lets you control the logo in the upper
left hand side of the docs.</p>
<pre><code class="language-rust ignore">#![doc(html_logo_url = &quot;https://example.com/logo.jpg&quot;)]
</code></pre>
<p>This will put <code>&lt;a href='index.html'&gt;&lt;img src='{}' alt='logo' width='100'&gt;&lt;/a&gt;</code> into
your docs, where the string for the attribute goes into the <code>{}</code>.</p>
<p>If you don't use this attribute, there will be no logo.</p>
<a class="header" href="the-doc-attribute.html#html_playground_url" id="html_playground_url"><h3><code>html_playground_url</code></h3></a>
<p>This form of the <code>doc</code> attribute lets you control where the &quot;run&quot; buttons
on your documentation examples make requests to.</p>
<pre><code class="language-rust ignore">#![doc(html_playground_url = &quot;https://playground.example.com/&quot;)]
</code></pre>
<p>Now, when you press &quot;run&quot;, the button will make a request to this domain.</p>
<p>If you don't use this attribute, there will be no run buttons.</p>
<a class="header" href="the-doc-attribute.html#issue_tracker_base_url" id="issue_tracker_base_url"><h3><code>issue_tracker_base_url</code></h3></a>
<p>This form of the <code>doc</code> attribute is mostly only useful for the standard library;
When a feature is unstable, an issue number for tracking the feature must be
given. <code>rustdoc</code> uses this number, plus the base URL given here, to link to
the tracking issue.</p>
<pre><code class="language-rust ignore">#![doc(issue_tracker_base_url = &quot;https://github.com/rust-lang/rust/issues/&quot;)]
</code></pre>
<a class="header" href="the-doc-attribute.html#html_no_source" id="html_no_source"><h3><code>html_no_source</code></h3></a>
<p>By default, <code>rustdoc</code> will include the source code of your program, with links
to it in the docs. But if you include this:</p>
<pre><code class="language-rust ignore">#![doc(html_no_source)]
</code></pre>
<p>it will not.</p>
<a class="header" href="the-doc-attribute.html#testno_crate_inject" id="testno_crate_inject"><h3><code>test(no_crate_inject)</code></h3></a>
<p>By default, <code>rustdoc</code> will automatically add a line with <code>extern crate my_crate;</code> into each doctest.
But if you include this:</p>
<pre><code class="language-rust ignore">#![doc(test(no_crate_inject))]
</code></pre>
<p>it will not.</p>
<a class="header" href="the-doc-attribute.html#testattr" id="testattr"><h3><code>test(attr(...))</code></h3></a>
<p>This form of the <code>doc</code> attribute allows you to add arbitrary attributes to all your doctests. For
example, if you want your doctests to fail if they produce any warnings, you could add this:</p>
<pre><code class="language-rust ignore">#![doc(test(attr(deny(warnings))))]
</code></pre>
<a class="header" href="the-doc-attribute.html#at-the-item-level" id="at-the-item-level"><h2>At the item level</h2></a>
<p>These forms of the <code>#[doc]</code> attribute are used on individual items, to control how
they are documented.</p>
<a class="header" href="the-doc-attribute.html#docno_inlinedocinline" id="docno_inlinedocinline"><h2><code>#[doc(no_inline)]</code>/<code>#[doc(inline)]</code></h2></a>
<p>These attributes are used on <code>use</code> statements, and control where the documentation shows
up. For example, consider this Rust code:</p>
<pre><code class="language-rust ignore">pub use bar::Bar;

/// bar docs
pub mod bar {
    /// the docs for Bar
    pub struct Bar;
}
</code></pre>
<p>The documentation will generate a &quot;Re-exports&quot; section, and say <code>pub use bar::Bar;</code>, where
<code>Bar</code> is a link to its page.</p>
<p>If we change the <code>use</code> line like this:</p>
<pre><code class="language-rust ignore">#[doc(inline)]
pub use bar::Bar;
</code></pre>
<p>Instead, <code>Bar</code> will appear in a <code>Structs</code> section, just like <code>Bar</code> was defined at the
top level, rather than <code>pub use</code>'d.</p>
<p>Let's change our original example, by making <code>bar</code> private:</p>
<pre><code class="language-rust ignore">pub use bar::Bar;

/// bar docs
mod bar {
    /// the docs for Bar
    pub struct Bar;
}
</code></pre>
<p>Here, because <code>bar</code> is not public, <code>Bar</code> wouldn't have its own page, so there's nowhere
to link to. <code>rustdoc</code> will inline these definitions, and so we end up in the same case
as the <code>#[doc(inline)]</code> above; <code>Bar</code> is in a <code>Structs</code> section, as if it were defined at
the top level. If we add the <code>no_inline</code> form of the attribute:</p>
<pre><code class="language-rust ignore">#[doc(no_inline)]
pub use bar::Bar;

/// bar docs
mod bar {
    /// the docs for Bar
    pub struct Bar;
}
</code></pre>
<p>Now we'll have a <code>Re-exports</code> line, and <code>Bar</code> will not link to anywhere.</p>
<a class="header" href="the-doc-attribute.html#dochidden" id="dochidden"><h2><code>#[doc(hidden)]</code></h2></a>
<p>Any item annotated with <code>#[doc(hidden)]</code> will not appear in the documentation, unless
the <code>strip-hidden</code> pass is removed.</p>
<a class="header" href="the-doc-attribute.html#docprimitive" id="docprimitive"><h2><code>#[doc(primitive)]</code></h2></a>
<p>Since primitive types are defined in the compiler, there's no place to attach documentation
attributes. This attribute is used by the standard library to provide a way to generate
documentation for primitive types.</p>

                    </main>

                    <nav class="nav-wrapper" aria-label="Page navigation">
                        <!-- Mobile navigation buttons -->
                        
                            <a rel="prev" href="command-line-arguments.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
                                <i class="fa fa-angle-left"></i>
                            </a>
                        

                        
                            <a rel="next" href="documentation-tests.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
                                <i class="fa fa-angle-right"></i>
                            </a>
                        

                        <div style="clear: both"></div>
                    </nav>
                </div>
            </div>

            <nav class="nav-wide-wrapper" aria-label="Page navigation">
                
                    <a href="command-line-arguments.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
                        <i class="fa fa-angle-left"></i>
                    </a>
                

                
                    <a href="documentation-tests.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
                        <i class="fa fa-angle-right"></i>
                    </a>
                
            </nav>

        </div>

        

        

        

        

        
        <script src="searchindex.js" type="text/javascript" charset="utf-8"></script>
        
        
        <script src="elasticlunr.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="mark.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="searcher.js" type="text/javascript" charset="utf-8"></script>
        

        <script src="clipboard.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="highlight.js" type="text/javascript" charset="utf-8"></script>
        <script src="book.js" type="text/javascript" charset="utf-8"></script>

        <!-- Custom JS scripts -->
        

    </body>
</html>