-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Added section on cargo new to "Hello Cargo!" chapter.
#22732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,8 @@ the Cargo | |
| README](https://github.com/rust-lang/cargo#installing-cargo-from-nightlies) | ||
| for specific instructions about installing it. | ||
|
|
||
| ## Converting to Cargo | ||
|
|
||
| Let's convert Hello World to Cargo. | ||
|
|
||
| To Cargo-ify our project, we need to do two things: Make a `Cargo.toml` | ||
|
|
@@ -103,6 +105,62 @@ That's it! We've successfully built `hello_world` with Cargo. Even though our | |
| program is simple, it's using much of the real tooling that you'll use for the | ||
| rest of your Rust career. | ||
|
|
||
| ## A New Project | ||
|
|
||
| You don't have to go through this whole process every time you want to start a new | ||
| project! Cargo has the ability to make a bare-bones project directory in which you | ||
| can start developing right away. | ||
|
|
||
| To start a new project with Cargo, use `cargo new`: | ||
|
|
||
| ```{bash} | ||
| $ cargo new hello_world --bin | ||
| ``` | ||
|
|
||
| We're passing `--bin` because we're making a binary program: if we | ||
| were making a library, we'd leave it off. | ||
|
|
||
| Let's check out what Cargo has generated for us: | ||
|
|
||
| ```{bash} | ||
| $ cd hello_world | ||
| $ tree . | ||
| . | ||
| ├── Cargo.toml | ||
| └── src | ||
| └── main.rs | ||
|
|
||
| 1 directory, 2 files | ||
| ``` | ||
|
|
||
| If you don't have the `tree` command, you can probably get it from your distro's package | ||
| manager. It's not necessary, but it's certainly useful. | ||
|
|
||
| This is all we need to get started. First, let's check out `Cargo.toml`: | ||
|
|
||
| ```{toml} | ||
| [package] | ||
|
|
||
| name = "hello_world" | ||
| version = "0.0.1" | ||
| authors = ["Your Name <[email protected]>"] | ||
| ``` | ||
|
|
||
| Cargo has populated this file with reasonable defaults based off the arguments | ||
| you gave it and your Git global config. You may notice that Cargo has also initialized | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and 'configuration' not 'config' |
||
| the `hello_world` directory as a Git repository. | ||
|
|
||
| Here's what's in `src/main.rs`: | ||
|
|
||
| ```{rust} | ||
| fn main() { | ||
| println!("Hello, world!"); | ||
| } | ||
| ``` | ||
|
|
||
| Cargo has generated a "Hello World!" for us, and you're ready to start coding! A | ||
| much more in-depth guide to Cargo can be found [here](http://doc.crates.io/guide.html). | ||
|
|
||
| Now that you've got the tools down, let's actually learn more about the Rust | ||
| language itself. These are the basics that will serve you well through the rest | ||
| of your time with Rust. | ||
| of your time with Rust. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{}s can be removed, this file still uses the old style, but i'd prefer to keep it the new style