Rollup merge of #27397 - Dangthrimble:master, r=steveklabnik
Clarifications for those new to Rust and Cargo: * It's a good idea to get rid of the original `main.exe` in project root * Slight clarification on the use of `main.rs` vs `lib.rs` * Clarify that the TOML file needs to be in project root
This commit is contained in:
commit
3e3a9b4eec
@ -98,8 +98,8 @@ use std::io;
|
||||
|
||||
We’ll need to take user input, and then print the result as output. As such, we
|
||||
need the `io` library from the standard library. Rust only imports a few things
|
||||
into every program, [the ‘prelude’][prelude]. If it’s not in the prelude,
|
||||
you’ll have to `use` it directly.
|
||||
by default into every program, [the ‘prelude’][prelude]. If it’s not in the
|
||||
prelude, you’ll have to `use` it directly.
|
||||
|
||||
[prelude]: ../std/prelude/index.html
|
||||
|
||||
|
@ -8,13 +8,13 @@ so it is assumed that Rust projects will use Cargo from the beginning.
|
||||
[cratesio]: http://doc.crates.io
|
||||
|
||||
Cargo manages three things: building your code, downloading the dependencies
|
||||
your code needs, and building those dependencies. At first, your
|
||||
program doesn’t have any dependencies, so we’ll only be using the first part of
|
||||
its functionality. Eventually, we’ll add more. Since we started off by using
|
||||
Cargo, it'll be easy to add later.
|
||||
your code needs, and building those dependencies. At first, your program doesn’t
|
||||
have any dependencies, so we’ll only be using the first part of its
|
||||
functionality. Eventually, we’ll add more. Since we started off by using Cargo,
|
||||
it'll be easy to add later.
|
||||
|
||||
If you installed Rust via the official installers you will also have Cargo. If
|
||||
you installed Rust some other way, you may want to [check the Cargo
|
||||
If we installed Rust via the official installers we will also have Cargo. If we
|
||||
installed Rust some other way, we may want to [check the Cargo
|
||||
README][cargoreadme] for specific instructions about installing it.
|
||||
|
||||
[cargoreadme]: https://github.com/rust-lang/cargo#installing-cargo-from-nightlies
|
||||
@ -23,20 +23,21 @@ README][cargoreadme] for specific instructions about installing it.
|
||||
|
||||
Let’s convert Hello World to Cargo.
|
||||
|
||||
To Cargo-ify our project, we need to do two things: Make a `Cargo.toml`
|
||||
configuration file, and put our source file in the right place. Let's
|
||||
do that part first:
|
||||
To Cargo-ify our project, we need to do three things: Make a `Cargo.toml`
|
||||
configuration file, put our source file in the right place, and get rid of the
|
||||
old executable (`main.exe` on Windows, `main` everywhere else). Let's do that part first:
|
||||
|
||||
```bash
|
||||
$ mkdir src
|
||||
$ mv main.rs src/main.rs
|
||||
$ rm main # or main.exe on Windows
|
||||
```
|
||||
|
||||
Note that since we're creating an executable, we used `main.rs`. If we
|
||||
want to make a library instead, we should use `lib.rs`. This convention is required
|
||||
for Cargo to successfully compile our projects, but it can be overridden if we wish.
|
||||
Custom file locations for the entry point can be specified
|
||||
with a [`[lib]` or `[[bin]]`][crates-custom] key in the TOML file.
|
||||
Note that since we're creating an executable, we retain `main.rs` as the source
|
||||
filename. If we want to make a library instead, we should use `lib.rs`. This
|
||||
convention is used by Cargo to successfully compile our projects, but it can be
|
||||
overridden if we wish. Custom file locations for the entry point can be
|
||||
specified with a [`[lib]` or `[[bin]]`][crates-custom] key in the TOML file.
|
||||
|
||||
[crates-custom]: http://doc.crates.io/manifest.html#configuring-a-target
|
||||
|
||||
@ -63,8 +64,8 @@ version = "0.0.1"
|
||||
authors = [ "Your name <you@example.com>" ]
|
||||
```
|
||||
|
||||
This file is in the [TOML][toml] format. TOML is similar to INI, but has some
|
||||
extra goodies. According to the TOML docs,
|
||||
This file is in the [TOML][toml] format. TOML is similar to INI, but has some
|
||||
extra goodies. According to the TOML docs,
|
||||
|
||||
> TOML aims to be a minimal configuration file format that's easy to read due
|
||||
> to obvious semantics. TOML is designed to map unambiguously to a hash table.
|
||||
@ -73,7 +74,8 @@ extra goodies. According to the TOML docs,
|
||||
|
||||
[toml]: https://github.com/toml-lang/toml
|
||||
|
||||
Once you have this file in place, we should be ready to build! To do so, run:
|
||||
Once we have this file in place in our project's root directory, we should be
|
||||
ready to build! To do so, run:
|
||||
|
||||
```bash
|
||||
$ cargo build
|
||||
|
Loading…
x
Reference in New Issue
Block a user