Sophie

Sophie

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

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>Specifying Dependencies - The Cargo Book</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 class="affix"><a href="index.html">Introduction</a></li><li><a href="getting-started/index.html"><strong aria-hidden="true">1.</strong> Getting Started</a></li><li><ol class="section"><li><a href="getting-started/installation.html"><strong aria-hidden="true">1.1.</strong> Installation</a></li><li><a href="getting-started/first-steps.html"><strong aria-hidden="true">1.2.</strong> First Steps with Cargo</a></li></ol></li><li><a href="guide/index.html"><strong aria-hidden="true">2.</strong> Cargo Guide</a></li><li><ol class="section"><li><a href="guide/why-cargo-exists.html"><strong aria-hidden="true">2.1.</strong> Why Cargo Exists</a></li><li><a href="guide/creating-a-new-project.html"><strong aria-hidden="true">2.2.</strong> Creating a New Project</a></li><li><a href="guide/working-on-an-existing-project.html"><strong aria-hidden="true">2.3.</strong> Working on an Existing Project</a></li><li><a href="guide/dependencies.html"><strong aria-hidden="true">2.4.</strong> Dependencies</a></li><li><a href="guide/project-layout.html"><strong aria-hidden="true">2.5.</strong> Project Layout</a></li><li><a href="guide/cargo-toml-vs-cargo-lock.html"><strong aria-hidden="true">2.6.</strong> Cargo.toml vs Cargo.lock</a></li><li><a href="guide/tests.html"><strong aria-hidden="true">2.7.</strong> Tests</a></li><li><a href="guide/continuous-integration.html"><strong aria-hidden="true">2.8.</strong> Continuous Integration</a></li><li><a href="guide/build-cache.html"><strong aria-hidden="true">2.9.</strong> Build Cache</a></li></ol></li><li><a href="reference/index.html"><strong aria-hidden="true">3.</strong> Cargo Reference</a></li><li><ol class="section"><li><a href="reference/specifying-dependencies.html" class="active"><strong aria-hidden="true">3.1.</strong> Specifying Dependencies</a></li><li><a href="reference/manifest.html"><strong aria-hidden="true">3.2.</strong> The Manifest Format</a></li><li><a href="reference/config.html"><strong aria-hidden="true">3.3.</strong> Configuration</a></li><li><a href="reference/environment-variables.html"><strong aria-hidden="true">3.4.</strong> Environment Variables</a></li><li><a href="reference/build-scripts.html"><strong aria-hidden="true">3.5.</strong> Build Scripts</a></li><li><a href="reference/publishing.html"><strong aria-hidden="true">3.6.</strong> Publishing on crates.io</a></li><li><a href="reference/pkgid-spec.html"><strong aria-hidden="true">3.7.</strong> Package ID Specifications</a></li><li><a href="reference/source-replacement.html"><strong aria-hidden="true">3.8.</strong> Source Replacement</a></li><li><a href="reference/external-tools.html"><strong aria-hidden="true">3.9.</strong> External Tools</a></li><li><a href="reference/unstable.html"><strong aria-hidden="true">3.10.</strong> Unstable Features</a></li></ol></li><li><a href="faq.html"><strong aria-hidden="true">4.</strong> FAQ</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">The Cargo Book</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="reference/specifying-dependencies.html#specifying-dependencies" id="specifying-dependencies"><h2>Specifying Dependencies</h2></a>
<p>Your crates can depend on other libraries from <a href="https://crates.io/">crates.io</a>, <code>git</code> repositories, or
subdirectories on your local file system. You can also temporarily override the
location of a dependency— for example, to be able to test out a bug fix in the
dependency that you are working on locally. You can have different
dependencies for different platforms, and dependencies that are only used during
development. Let's take a look at how to do each of these.</p>
<a class="header" href="reference/specifying-dependencies.html#specifying-dependencies-from-cratesio" id="specifying-dependencies-from-cratesio"><h3>Specifying dependencies from crates.io</h3></a>
<p>Cargo is configured to look for dependencies on <a href="https://crates.io/">crates.io</a> by default. Only
the name and a version string are required in this case. In <a href="guide/index.html">the cargo
guide</a>, we specified a dependency on the <code>time</code> crate:</p>
<pre><code class="language-toml">[dependencies]
time = &quot;0.1.12&quot;
</code></pre>
<p>The string <code>&quot;0.1.12&quot;</code> is a <a href="https://github.com/steveklabnik/semver#requirements">semver</a> version requirement. Since this
string does not have any operators in it, it is interpreted the same way as
if we had specified <code>&quot;^0.1.12&quot;</code>, which is called a caret requirement.</p>
<a class="header" href="reference/specifying-dependencies.html#caret-requirements" id="caret-requirements"><h3>Caret requirements</h3></a>
<p><strong>Caret requirements</strong> allow SemVer compatible updates to a specified version.
An update is allowed if the new version number does not modify the left-most
non-zero digit in the major, minor, patch grouping. In this case, if we ran
<code>cargo update -p time</code>, cargo should update us to version <code>0.1.13</code> if it is the
latest <code>0.1.z</code> release, but would not update us to <code>0.2.0</code>. If instead we had
specified the version string as <code>^1.0</code>, cargo should update to <code>1.1</code> if it is
the latest <code>1.y</code> release, but not <code>2.0</code>. The version <code>0.0.x</code> is not considered
compatible with any other version.</p>
<p>Here are some more examples of caret requirements and the versions that would
be allowed with them:</p>
<pre><code class="language-notrust">^1.2.3 := &gt;=1.2.3 &lt;2.0.0
^1.2 := &gt;=1.2.0 &lt;2.0.0
^1 := &gt;=1.0.0 &lt;2.0.0
^0.2.3 := &gt;=0.2.3 &lt;0.3.0
^0.2 := &gt;= 0.2.0 &lt; 0.3.0
^0.0.3 := &gt;=0.0.3 &lt;0.0.4
^0.0 := &gt;=0.0.0 &lt;0.1.0
^0 := &gt;=0.0.0 &lt;1.0.0
</code></pre>
<p>This compatibility convention is different from SemVer in the way it treats
versions before 1.0.0. While SemVer says there is no compatibility before
1.0.0, Cargo considers <code>0.x.y</code> to be compatible with <code>0.x.z</code>, where <code>y ≥ z</code>
and <code>x &gt; 0</code>.</p>
<a class="header" href="reference/specifying-dependencies.html#tilde-requirements" id="tilde-requirements"><h3>Tilde requirements</h3></a>
<p><strong>Tilde requirements</strong> specify a minimal version with some ability to update.
If you specify a major, minor, and patch version or only a major and minor
version, only patch-level changes are allowed. If you only specify a major
version, then minor- and patch-level changes are allowed.</p>
<p><code>~1.2.3</code> is an example of a tilde requirement.</p>
<pre><code class="language-notrust">~1.2.3 := &gt;=1.2.3 &lt;1.3.0
~1.2 := &gt;=1.2.0 &lt;1.3.0
~1 := &gt;=1.0.0 &lt;2.0.0
</code></pre>
<a class="header" href="reference/specifying-dependencies.html#wildcard-requirements" id="wildcard-requirements"><h3>Wildcard requirements</h3></a>
<p><strong>Wildcard requirements</strong> allow for any version where the wildcard is
positioned.</p>
<p><code>*</code>, <code>1.*</code> and <code>1.2.*</code> are examples of wildcard requirements.</p>
<pre><code class="language-notrust">* := &gt;=0.0.0
1.* := &gt;=1.0.0 &lt;2.0.0
1.2.* := &gt;=1.2.0 &lt;1.3.0
</code></pre>
<a class="header" href="reference/specifying-dependencies.html#inequality-requirements" id="inequality-requirements"><h3>Inequality requirements</h3></a>
<p><strong>Inequality requirements</strong> allow manually specifying a version range or an
exact version to depend on.</p>
<p>Here are some examples of inequality requirements:</p>
<pre><code class="language-notrust">&gt;= 1.2.0
&gt; 1
&lt; 2
= 1.2.3
</code></pre>
<a class="header" href="reference/specifying-dependencies.html#multiple-requirements" id="multiple-requirements"><h3>Multiple requirements</h3></a>
<p>Multiple version requirements can also be separated with a comma, e.g. <code>&gt;= 1.2, &lt; 1.5</code>.</p>
<a class="header" href="reference/specifying-dependencies.html#specifying-dependencies-from-git-repositories" id="specifying-dependencies-from-git-repositories"><h3>Specifying dependencies from <code>git</code> repositories</h3></a>
<p>To depend on a library located in a <code>git</code> repository, the minimum information
you need to specify is the location of the repository with the <code>git</code> key:</p>
<pre><code class="language-toml">[dependencies]
rand = { git = &quot;https://github.com/rust-lang-nursery/rand&quot; }
</code></pre>
<p>Cargo will fetch the <code>git</code> repository at this location then look for a
<code>Cargo.toml</code> for the requested crate anywhere inside the <code>git</code> repository
(not necessarily at the root).</p>
<p>Since we haven’t specified any other information, Cargo assumes that
we intend to use the latest commit on the <code>master</code> branch to build our project.
You can combine the <code>git</code> key with the <code>rev</code>, <code>tag</code>, or <code>branch</code> keys to
specify something else. Here's an example of specifying that you want to use
the latest commit on a branch named <code>next</code>:</p>
<pre><code class="language-toml">[dependencies]
rand = { git = &quot;https://github.com/rust-lang-nursery/rand&quot;, branch = &quot;next&quot; }
</code></pre>
<a class="header" href="reference/specifying-dependencies.html#specifying-path-dependencies" id="specifying-path-dependencies"><h3>Specifying path dependencies</h3></a>
<p>Over time, our <code>hello_world</code> project from <a href="guide/index.html">the guide</a> has
grown significantly in size! It’s gotten to the point that we probably want to
split out a separate crate for others to use. To do this Cargo supports <strong>path
dependencies</strong> which are typically sub-crates that live within one repository.
Let’s start off by making a new crate inside of our <code>hello_world</code> project:</p>
<pre><code class="language-console"># inside of hello_world/
$ cargo new hello_utils
</code></pre>
<p>This will create a new folder <code>hello_utils</code> inside of which a <code>Cargo.toml</code> and
<code>src</code> folder are ready to be configured. In order to tell Cargo about this, open
up <code>hello_world/Cargo.toml</code> and add <code>hello_utils</code> to your dependencies:</p>
<pre><code class="language-toml">[dependencies]
hello_utils = { path = &quot;hello_utils&quot; }
</code></pre>
<p>This tells Cargo that we depend on a crate called <code>hello_utils</code> which is found
in the <code>hello_utils</code> folder (relative to the <code>Cargo.toml</code> it’s written in).</p>
<p>And that’s it! The next <code>cargo build</code> will automatically build <code>hello_utils</code> and
all of its own dependencies, and others can also start using the crate as well.
However, crates that use dependencies specified with only a path are not
permitted on <a href="https://crates.io/">crates.io</a>. If we wanted to publish our <code>hello_world</code> crate, we
would need to publish a version of <code>hello_utils</code> to <a href="https://crates.io">crates.io</a>
and specify its version in the dependencies line as well:</p>
<pre><code class="language-toml">[dependencies]
hello_utils = { path = &quot;hello_utils&quot;, version = &quot;0.1.0&quot; }
</code></pre>
<a class="header" href="reference/specifying-dependencies.html#overriding-dependencies" id="overriding-dependencies"><h3>Overriding dependencies</h3></a>
<p>There are a number of methods in Cargo to support overriding dependencies and
otherwise controlling the dependency graph. These options are typically, though,
only available at the workspace level and aren't propagated through
dependencies. In other words, &quot;applications&quot; have the ability to override
dependencies but &quot;libraries&quot; do not.</p>
<p>The desire to override a dependency or otherwise alter some dependencies can
arise through a number of scenarios. Most of them, however, boil down to the
ability to work with a crate before it's been published to crates.io. For
example:</p>
<ul>
<li>A crate you're working on is also used in a much larger application you're
working on, and you'd like to test a bug fix to the library inside of the
larger application.</li>
<li>An upstream crate you don't work on has a new feature or a bug fix on the
master branch of its git repository which you'd like to test out.</li>
<li>You're about to publish a new major version of your crate, but you'd like to
do integration testing across an entire project to ensure the new major
version works.</li>
<li>You've submitted a fix to an upstream crate for a bug you found, but you'd
like to immediately have your application start depending on the fixed version
of the crate to avoid blocking on the bug fix getting merged.</li>
</ul>
<p>These scenarios are currently all solved with the <a href="reference/manifest.html#the-patch-section"><code>[patch]</code> manifest
section</a>. Historically some of these scenarios have been solved
with <a href="reference/manifest.html#the-replace-section">the <code>[replace]</code> section</a>, but we'll document the <code>[patch]</code>
section here.</p>
<a class="header" href="reference/specifying-dependencies.html#testing-a-bugfix" id="testing-a-bugfix"><h3>Testing a bugfix</h3></a>
<p>Let's say you're working with the [<code>uuid</code>] crate but while you're working on it
you discover a bug. You are, however, quite enterprising so you decide to also
try out to fix the bug! Originally your manifest will look like:</p>
<p><a href="https://crates.io/crates/uuid"><code>uuid</code></a></p>
<pre><code class="language-toml">[package]
name = &quot;my-library&quot;
version = &quot;0.1.0&quot;
authors = [&quot;...&quot;]

[dependencies]
uuid = &quot;1.0&quot;
</code></pre>
<p>First thing we'll do is to clone the <a href="https://github.com/rust-lang-nursery/uuid"><code>uuid</code> repository</a>
locally via:</p>
<pre><code class="language-console">$ git clone https://github.com/rust-lang-nursery/uuid
</code></pre>
<p>Next we'll edit the manifest of <code>my-library</code> to contain:</p>
<pre><code class="language-toml">[patch.crates-io]
uuid = { path = &quot;../path/to/uuid&quot; }
</code></pre>
<p>Here we declare that we're <em>patching</em> the source <code>crates-io</code> with a new
dependency. This will effectively add the local checked out version of <code>uuid</code> to
the crates.io registry for our local project.</p>
<p>Next up we need to ensure that our lock file is updated to use this new version
of <code>uuid</code> so our project uses the locally checked out copy instead of one from
crates.io. The way <code>[patch]</code> works is that it'll load the dependency at
<code>../path/to/uuid</code> and then whenever crates.io is queried for versions of <code>uuid</code>
it'll <em>also</em> return the local version.</p>
<p>This means that the version number of the local checkout is significant and will
affect whether the patch is used. Our manifest declared <code>uuid = &quot;1.0&quot;</code> which
means we'll only resolve to <code>&gt;= 1.0.0, &lt; 2.0.0</code>, and Cargo's greedy resolution
algorithm also means that we'll resolve to the maximum version within that
range. Typically this doesn't matter as the version of the git repository will
already be greater or match the maximum version published on crates.io, but it's
important to keep this in mind!</p>
<p>In any case, typically all you need to do now is:</p>
<pre><code class="language-console">$ cargo build
   Compiling uuid v1.0.0 (file://.../uuid)
   Compiling my-library v0.1.0 (file://.../my-library)
    Finished dev [unoptimized + debuginfo] target(s) in 0.32 secs
</code></pre>
<p>And that's it! You're now building with the local version of <code>uuid</code> (note the
<code>file://</code> in the build output). If you don't see the <code>file://</code> version getting
built then you may need to run <code>cargo update -p uuid --precise $version</code> where
<code>$version</code> is the version of the locally checked out copy of <code>uuid</code>.</p>
<p>Once you've fixed the bug you originally found the next thing you'll want to do
is to likely submit that as a pull request to the <code>uuid</code> crate itself. Once
you've done this then you can also update the <code>[patch]</code> section. The listing
inside of <code>[patch]</code> is just like the <code>[dependencies]</code> section, so once your pull
request is merged you could change your <code>path</code> dependency to:</p>
<pre><code class="language-toml">[patch.crates-io]
uuid = { git = 'https://github.com/rust-lang-nursery/uuid' }
</code></pre>
<a class="header" href="reference/specifying-dependencies.html#working-with-an-unpublished-minor-version" id="working-with-an-unpublished-minor-version"><h3>Working with an unpublished minor version</h3></a>
<p>Let's now shift gears a bit from bug fixes to adding features. While working on
<code>my-library</code> you discover that a whole new feature is needed in the <code>uuid</code>
crate. You've implemented this feature, tested it locally above with <code>[patch]</code>,
and submitted a pull request. Let's go over how you continue to use and test it
before it's actually published.</p>
<p>Let's also say that the current version of <code>uuid</code> on crates.io is <code>1.0.0</code>, but
since then the master branch of the git repository has updated to <code>1.0.1</code>. This
branch includes your new feature you submitted previously. To use this
repository we'll edit our <code>Cargo.toml</code> to look like</p>
<pre><code class="language-toml">[package]
name = &quot;my-library&quot;
version = &quot;0.1.0&quot;
authors = [&quot;...&quot;]

[dependencies]
uuid = &quot;1.0.1&quot;

[patch.crates-io]
uuid = { git = 'https://github.com/rust-lang-nursery/uuid' }
</code></pre>
<p>Note that our local dependency on <code>uuid</code> has been updated to <code>1.0.1</code> as it's
what we'll actually require once the crate is published. This version doesn't
exist on crates.io, though, so we provide it with the <code>[patch]</code> section of the
manifest.</p>
<p>Now when our library is built it'll fetch <code>uuid</code> from the git repository and
resolve to 1.0.1 inside the repository instead of trying to download a version
from crates.io. Once 1.0.1 is published on crates.io the <code>[patch]</code> section can
be deleted.</p>
<p>It's also worth noting that <code>[patch]</code> applies <em>transitively</em>. Let's say you use
<code>my-library</code> in a larger project, such as:</p>
<pre><code class="language-toml">[package]
name = &quot;my-binary&quot;
version = &quot;0.1.0&quot;
authors = [&quot;...&quot;]

[dependencies]
my-library = { git = 'https://example.com/git/my-library' }
uuid = &quot;1.0&quot;

[patch.crates-io]
uuid = { git = 'https://github.com/rust-lang-nursery/uuid' }
</code></pre>
<p>Remember that <code>[patch]</code> is applicable <em>transitively</em> but can only be defined at
the <em>top level</em> so we consumers of <code>my-library</code> have to repeat the <code>[patch]</code> section
if necessary. Here, though, the new <code>uuid</code> crate applies to <em>both</em> our dependency on
<code>uuid</code> and the <code>my-library -&gt; uuid</code> dependency. The <code>uuid</code> crate will be resolved to
one version for this entire crate graph, 1.0.1, and it'll be pulled from the git
repository.</p>
<a class="header" href="reference/specifying-dependencies.html#overriding-repository-url" id="overriding-repository-url"><h4>Overriding repository URL</h4></a>
<p>In case the dependency you want to override isn't loaded from <code>crates.io</code>, you'll have to change a bit how you use <code>[patch]</code>:</p>
<pre><code class="language-toml">[patch.&quot;https://github.com/your/repository&quot;]
my-library = { path = &quot;../my-library/path&quot; }
</code></pre>
<p>And that's it!</p>
<a class="header" href="reference/specifying-dependencies.html#prepublishing-a-breaking-change" id="prepublishing-a-breaking-change"><h3>Prepublishing a breaking change</h3></a>
<p>As a final scenario, let's take a look at working with a new major version of a
crate, typically accompanied with breaking changes. Sticking with our previous
crates, this means that we're going to be creating version 2.0.0 of the <code>uuid</code>
crate. After we've submitted all changes upstream we can update our manifest for
<code>my-library</code> to look like:</p>
<pre><code class="language-toml">[dependencies]
uuid = &quot;2.0&quot;

[patch.crates-io]
uuid = { git = &quot;https://github.com/rust-lang-nursery/uuid&quot;, branch = &quot;2.0.0&quot; }
</code></pre>
<p>And that's it! Like with the previous example the 2.0.0 version doesn't actually
exist on crates.io but we can still put it in through a git dependency through
the usage of the <code>[patch]</code> section. As a thought exercise let's take another
look at the <code>my-binary</code> manifest from above again as well:</p>
<pre><code class="language-toml">[package]
name = &quot;my-binary&quot;
version = &quot;0.1.0&quot;
authors = [&quot;...&quot;]

[dependencies]
my-library = { git = 'https://example.com/git/my-library' }
uuid = &quot;1.0&quot;

[patch.crates-io]
uuid = { git = 'https://github.com/rust-lang-nursery/uuid', version = '2.0.0' }
</code></pre>
<p>Note that this will actually resolve to two versions of the <code>uuid</code> crate. The
<code>my-binary</code> crate will continue to use the 1.x.y series of the <code>uuid</code> crate but
the <code>my-library</code> crate will use the 2.0.0 version of <code>uuid</code>. This will allow you
to gradually roll out breaking changes to a crate through a dependency graph
without being force to update everything all at once.</p>
<a class="header" href="reference/specifying-dependencies.html#overriding-with-local-dependencies" id="overriding-with-local-dependencies"><h3>Overriding with local dependencies</h3></a>
<p>Sometimes you're only temporarily working on a crate and you don't want to have
to modify <code>Cargo.toml</code> like with the <code>[patch]</code> section above. For this use
case Cargo offers a much more limited version of overrides called <strong>path
overrides</strong>.</p>
<p>Path overrides are specified through <code>.cargo/config</code> instead of <code>Cargo.toml</code>,
and you can find <a href="reference/config.html">more documentation about this configuration</a>.
Inside of <code>.cargo/config</code> you'll specify a key called <code>paths</code>:</p>
<pre><code class="language-toml">paths = [&quot;/path/to/uuid&quot;]
</code></pre>
<p>This array should be filled with directories that contain a <code>Cargo.toml</code>. In
this instance, we’re just adding <code>uuid</code>, so it will be the only one that’s
overridden. This path can be either absolute or relative to the directory that
contains the <code>.cargo</code> folder.</p>
<p>Path overrides are more restricted than the <code>[patch]</code> section, however, in
that they cannot change the structure of the dependency graph. When a
path replacement is used then the previous set of dependencies
must all match exactly to the new <code>Cargo.toml</code> specification. For example this
means that path overrides cannot be used to test out adding a dependency to a
crate, instead <code>[patch]</code> must be used in that situation. As a result usage of a
path override is typically isolated to quick bug fixes rather than larger
changes.</p>
<p>Note: using a local configuration to override paths will only work for crates
that have been published to <a href="https://crates.io/">crates.io</a>. You cannot use this feature to tell
Cargo how to find local unpublished crates.</p>
<a class="header" href="reference/specifying-dependencies.html#platform-specific-dependencies" id="platform-specific-dependencies"><h3>Platform specific dependencies</h3></a>
<p>Platform-specific dependencies take the same format, but are listed under a
<code>target</code> section. Normally Rust-like <code>#[cfg]</code> syntax will be used to define
these sections:</p>
<pre><code class="language-toml">[target.'cfg(windows)'.dependencies]
winhttp = &quot;0.4.0&quot;

[target.'cfg(unix)'.dependencies]
openssl = &quot;1.0.1&quot;

[target.'cfg(target_arch = &quot;x86&quot;)'.dependencies]
native = { path = &quot;native/i686&quot; }

[target.'cfg(target_arch = &quot;x86_64&quot;)'.dependencies]
native = { path = &quot;native/x86_64&quot; }
</code></pre>
<p>Like with Rust, the syntax here supports the <code>not</code>, <code>any</code>, and <code>all</code> operators
to combine various cfg name/value pairs. Note that the <code>cfg</code> syntax has only
been available since Cargo 0.9.0 (Rust 1.8.0).</p>
<p>In addition to <code>#[cfg]</code> syntax, Cargo also supports listing out the full target
the dependencies would apply to:</p>
<pre><code class="language-toml">[target.x86_64-pc-windows-gnu.dependencies]
winhttp = &quot;0.4.0&quot;

[target.i686-unknown-linux-gnu.dependencies]
openssl = &quot;1.0.1&quot;
</code></pre>
<p>If you’re using a custom target specification, quote the full path and file
name:</p>
<pre><code class="language-toml">[target.&quot;x86_64/windows.json&quot;.dependencies]
winhttp = &quot;0.4.0&quot;

[target.&quot;i686/linux.json&quot;.dependencies]
openssl = &quot;1.0.1&quot;
native = { path = &quot;native/i686&quot; }

[target.&quot;x86_64/linux.json&quot;.dependencies]
openssl = &quot;1.0.1&quot;
native = { path = &quot;native/x86_64&quot; }
</code></pre>
<a class="header" href="reference/specifying-dependencies.html#development-dependencies" id="development-dependencies"><h3>Development dependencies</h3></a>
<p>You can add a <code>[dev-dependencies]</code> section to your <code>Cargo.toml</code> whose format
is equivalent to <code>[dependencies]</code>:</p>
<pre><code class="language-toml">[dev-dependencies]
tempdir = &quot;0.3&quot;
</code></pre>
<p>Dev-dependencies are not used when compiling
a package for building, but are used for compiling tests, examples, and
benchmarks.</p>
<p>These dependencies are <em>not</em> propagated to other packages which depend on this
package.</p>
<p>You can also have target-specific development dependencies by using
<code>dev-dependencies</code> in the target section header instead of <code>dependencies</code>. For
example:</p>
<pre><code class="language-toml">[target.'cfg(unix)'.dev-dependencies]
mio = &quot;0.0.1&quot;
</code></pre>
<a class="header" href="reference/specifying-dependencies.html#build-dependencies" id="build-dependencies"><h3>Build dependencies</h3></a>
<p>You can depend on other Cargo-based crates for use in your build scripts.
Dependencies are declared through the <code>build-dependencies</code> section of the
manifest:</p>
<pre><code class="language-toml">[build-dependencies]
cc = &quot;1.0.3&quot;
</code></pre>
<p>The build script <strong>does not</strong> have access to the dependencies listed
in the <code>dependencies</code> or <code>dev-dependencies</code> section. Build
dependencies will likewise not be available to the package itself
unless listed under the <code>dependencies</code> section as well. A package
itself and its build script are built separately, so their
dependencies need not coincide. Cargo is kept simpler and cleaner by
using independent dependencies for independent purposes.</p>
<a class="header" href="reference/specifying-dependencies.html#choosing-features" id="choosing-features"><h3>Choosing features</h3></a>
<p>If a package you depend on offers conditional features, you can
specify which to use:</p>
<pre><code class="language-toml">[dependencies.awesome]
version = &quot;1.3.5&quot;
default-features = false # do not include the default features, and optionally
                         # cherry-pick individual features
features = [&quot;secure-password&quot;, &quot;civet&quot;]
</code></pre>
<p>More information about features can be found in the
<a href="reference/manifest.html#the-features-section">manifest documentation</a>.</p>

                    </main>

                    <nav class="nav-wrapper" aria-label="Page navigation">
                        <!-- Mobile navigation buttons -->
                        
                            <a rel="prev" href="reference/index.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="reference/manifest.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="reference/index.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="reference/manifest.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>