Sophie

Sophie

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

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

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="generator" content="rustdoc">
    <title>Conditional Compilation</title>

    <link rel="stylesheet" type="text/css" href="../rust.css">

    <link rel="shortcut icon" href="https://www.rust-lang.org/favicon.ico">


</head>
<body class="rustdoc">
    <!--[if lte IE 8]>
    <div class="warning">
        This old browser is unsupported and will most likely display funky
        things.
    </div>
    <![endif]-->

    <div id="versioninfo">
  <img src="https://www.rust-lang.org/logos/rust-logo-32x32-blk.png" width="32" height="32" alt="Rust logo"><br>
  <span class="white-sticker"><a href="https://www.rust-lang.org">Rust</a> 1.28.0</span><br>
  <a href="https://github.com/rust-lang/rust/commit/"
    class="hash white-sticker"></a>
</div>


    <h1 class="title">Conditional Compilation</h1>
    <p><small>There is a new edition of the book and this is an old link.</small></p>
<blockquote>
<p>Sometimes one wants to have different compiler outputs from the same code, depending on build target, such as targeted operating system, or to enable release builds.
Configuration options are either provided by the compiler or passed in on the command line using.
Rust code then checks for their presence using the <code>#[cfg(...)]</code> attribute</p>
</blockquote>

<pre class="rust rust-example-rendered">
<span class="comment">// The function is only included in the build when compiling for macOS</span>
<span class="attribute">#[<span class="ident">cfg</span>(<span class="ident">target_os</span> <span class="op">=</span> <span class="string">&quot;macos&quot;</span>)]</span>
<span class="kw">fn</span> <span class="ident">macos_only</span>() {
  <span class="comment">// ...</span>
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0A%2F%2F%20The%20function%20is%20only%20included%20in%20the%20build%20when%20compiling%20for%20macOS%0A%23%5Bcfg(target_os%20%3D%20%22macos%22)%5D%0Afn%20macos_only()%20%7B%0A%20%20%2F%2F%20...%0A%7D%0A%7D">Run</a></pre>
<hr />
<p>This particular chapter does not exist in <a href="second-edition/index.html">the second edition</a>.
The best place to learn about it is <a href="../reference/attributes.html#conditional-compilation">the Rust Reference</a>.</p>
<ul>
<li><strong><a href="../reference/attributes.html#conditional-compilation">In the Rust Reference: Ch 5.3 — Attributes, Conditional Compilation section</a></strong></li>
<li><small><a href="first-edition/conditional-compilation.html">In the first edition: Ch 4.3 — Conditional Compilation</a></small></li>
</ul>

    <footer><p>
Copyright &copy; 2011 The Rust Project Developers. Licensed under the
<a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>
or the <a href="https://opensource.org/licenses/MIT">MIT license</a>, at your option.
</p><p>
This file may not be copied, modified, or distributed except according to those terms.
</p></footer>


</body>
</html>