[mdBook]: https://github.com/azerupi/mdBook
-```shell
+```console
$ cargo install mdbook
```
To build the book:
-```shell
+```console
$ mdbook build
```
your web browser.
_Firefox:_
-```shell
+```console
$ firefox book/index.html # Linux
$ open -a "Firefox" book/index.html # OS X
$ Start-Process "firefox.exe" .\book\index.html # Windows (PowerShell)
```
_Chrome:_
-```shell
+```console
$ google-chrome book/index.html # Linux
$ open -a "Google Chrome" book/index.html # OS X
$ Start-Process "chrome.exe" .\book\index.html # Windows (PowerShell)
To start a new project with Cargo, use `cargo new`:
-```shell
+```console
$ cargo new hello_world --bin
```
Let’s check out what Cargo has generated for us:
-```shell
+```console
$ cd hello_world
$ tree .
.
Cargo generated a “hello world” for us. Let’s compile it:
-```shell
+```console
$ cargo build
Compiling hello_world v0.1.0 (file:///path/to/project/hello_world)
```
And then run it:
-```shell
+```console
$ ./target/debug/hello_world
Hello, world!
```
We can also use `cargo run` to compile and then run it, all in one step:
-```shell
+```console
$ cargo run
Fresh hello_world v0.1.0 (file:///path/to/project/hello_world)
Running `target/hello_world`
The easiest way to get Cargo is to get the current stable release of [Rust] by
using the `rustup` script:
-```shell
+```console
$ curl -sSf https://static.rust-lang.org/rustup.sh | sh
```
When we’re ready to opt in to a new version of the library, Cargo can
re-calculate the dependencies and update things for us:
-```shell
+```console
$ cargo update # updates all dependencies
$ cargo update -p rand # updates just “rand”
```
To start a new project with Cargo, use `cargo new`:
-```shell
+```console
$ cargo new hello_world --bin
```
Let’s check out what Cargo has generated for us:
-```shell
+```console
$ cd hello_world
$ tree .
.
Cargo generated a “hello world” for us. Let’s compile it:
-```shell
+```console
$ cargo build
Compiling hello_world v0.1.0 (file:///path/to/project/hello_world)
```
And then run it:
-```shell
+```console
$ ./target/debug/hello_world
Hello, world!
```
won't see the `Compiling` line if you have not made any changes since you last
compiled):
-```shell
+```console
$ cargo run
Compiling hello_world v0.1.0 (file:///path/to/project/hello_world)
Running `target/debug/hello_world`
Once you’re ready for release, you can use `cargo build --release` to compile
your files with optimizations turned on:
-```shell
+```console
$ cargo build --release
Compiling hello_world v0.1.0 (file:///path/to/project/hello_world)
```
Re-run `cargo build`, and Cargo will fetch the new dependencies and all of
their dependencies, compile them all, and update the `Cargo.lock`:
-```shell
+```console
$ cargo build
Updating registry `https://github.com/rust-lang/crates.io-index`
Downloading memchr v0.1.5
Running it will show:
-```shell
+```console
$ cargo run
Running `target/hello_world`
Did our date match? true
Cargo uses conventions for file placement to make it easy to dive into a new
Cargo project:
-```shell
+```
.
├── Cargo.lock
├── Cargo.toml
Here's an example of running `cargo test` in our project, which currently has
no tests:
-```shell
+```console
$ cargo test
Compiling rand v0.1.0 (https://github.com/rust-lang-nursery/rand.git#9f35b8e)
Compiling hello_world v0.1.0 (file:///path/to/project/hello_world)
You can also run a specific test by passing a filter:
-```shell
+```console
$ cargo test foo
```
First, get the project from somewhere. In this example, we’ll use `rand`
cloned from its repository on GitHub:
-```shell
+```console
$ git clone https://github.com/rust-lang-nursery/rand.git
$ cd rand
```
To build, use `cargo build`:
-```shell
+```console
$ cargo build
Compiling rand v0.1.0 (file:///path/to/project/rand)
```
Any line that starts with `cargo:` is interpreted directly by Cargo.
This line must be of the form `cargo:key=value`, like the examples below:
-```shell
+```
# specially recognized by Cargo
cargo:rustc-link-lib=static=foo
cargo:rustc-link-search=native=/path/to/foo
First, let’s take a look at the directory structure of this package:
-```shell
+```
.
├── Cargo.toml
├── build.rs
Like above, let’s first take a look at the project layout:
-```shell
+```
.
├── Cargo.toml
├── build.rs
In that case, Servo will describe features in its `Cargo.toml` and they can be
enabled using command-line flags:
-```shell
+```console
$ cargo build --release --features "shumway pdf"
```
integration tests, and benchmarks respectively. Analogous to `bin` targets, they
may be composed of single files or directories with a `main.rs` file.
-```shell
+```
▾ src/ # directory containing source files
lib.rs # the main entry point for libraries and packages
main.rs # the main entry point for projects producing executables
Settings](https://crates.io/me) page and run the `cargo login` command
specified.
-```shell
+```console
$ cargo login abcdefghijklmnopqrstuvwxyz012345
```
our entire crate and package it all up into a `*.crate` file in the
`target/package` directory.
-```shell
+```console
$ cargo package
```
[crates.io] with the `cargo publish` command. And that’s it, you’ve now published
your first crate!
-```shell
+```console
$ cargo publish
```
etc.). For situations such as this, Cargo supports a “yank” of a version of a
crate.
-```shell
+```console
$ cargo yank --vers 1.0.1
$ cargo yank --vers 1.0.1 --undo
```
may change over time! The owner of a crate is the only person allowed to publish
new versions of the crate, but an owner may designate additional owners.
-```shell
+```console
$ cargo owner --add my-buddy
$ cargo owner --remove my-buddy
$ cargo owner --add github:rust-lang:owners
dependencies** which are typically sub-crates that live within one repository.
Let’s start off by making a new crate inside of our `hello_world` project:
-```shell
+```console
# inside of hello_world/
$ cargo new hello_utils
```
First thing we'll do is to clone the [`uuid` repository][uuid-repository]
locally via:
-```shell
+```console
$ git clone https://github.com/rust-lang-nursery/uuid
```
In any case, typically all you need to do now is:
-```shell
+```console
$ cargo build
Compiling uuid v1.0.0 (file://.../uuid)
Compiling my-library v0.1.0 (file://.../my-library)