rust_notebooks/01_geting_started/.ipynb_checkpoints/02_Hello_Cargo-checkpoint.i...

66 lines
3.2 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"cells": [
{
"cell_type": "markdown",
"id": "670184c1-8f72-475b-94a3-0d9f49eff4d2",
"metadata": {},
"source": [
"## Hello, Cargo!\n",
"\n",
"Cargo is Rusts build system and package manager. Most Rustaceans use this tool to manage their Rust projects because Cargo handles a lot of tasks for you, such as building your code, downloading the libraries your code depends on, and building those libraries. (We call the libraries that your code needs *dependencies*.)\n",
"\n",
"The simplest Rust programs, like the one weve written so far, dont have any dependencies. If we had built the “Hello, world!” project with Cargo, it would only use the part of Cargo that handles building your code. As you write more complex Rust programs, youll add dependencies, and if you start a project using Cargo, adding dependencies will be much easier to do.\n",
"\n",
"Because the vast majority of Rust projects use Cargo, the rest of this book assumes that youre using Cargo too. Cargo comes installed with Rust if you used the official installers discussed in the `“Installation”` section. If you installed Rust through some other means, check whether Cargo is installed by entering the following in your terminal:\n",
"\n",
"```sh\n",
"$ cargo --version\n",
"```\n",
"\n",
"If you see a version number, you have it! If you see an error, such as `command not found`, look at the documentation for your method of installation to determine how to install Cargo separately.\n",
"\n",
"### Creating a Project with Cargo\n",
"\n",
"Lets create a new project using Cargo and look at how it differs from our original “Hello, world!” project. Navigate back to your *projects* directory (or wherever you decided to store your code). Then, on any operating system, run the following:\n",
"\n",
"```sh\n",
"$ cargo new hello_cargo\n",
"$ cd hello_cargo\n",
"```\n",
"\n",
"The first command creates a new directory and project called *hello_cargo*. Weve named our project *hello_cargo*, and Cargo creates its files in a directory of the same name.\n",
"\n",
"Go into the *hello_cargo* directory and list the files. Youll see that Cargo has generated two files and one directory for us: a *Cargo.toml* file and a src directory with a *main.rs* file inside.\n",
"\n",
"It has also initialized a new Git repository along with a *.gitignore* file. Git files wont be generated if you `run cargo` new within an existing Git repository; you can override this behavior by using `cargo new --vcs=git`\n",
"\n",
"<details>\n",
" <sumary>more details</sumary>\n",
"\n",
" ### sdaf\n",
" Open Cargo.toml in your text editor of choice. It should look similar to the code in Listing 1-2.\n",
"\n",
" Filename: Cargo.toml\n",
"</details>"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Rust",
"language": "rust",
"name": "rust"
},
"language_info": {
"codemirror_mode": "rust",
"file_extension": ".rs",
"mimetype": "text/rust",
"name": "Rust",
"pygment_lexer": "rust",
"version": ""
}
},
"nbformat": 4,
"nbformat_minor": 5
}