Skip to content

Latest commit

Β 

History

History

hello-world-cargo

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Β 
Β 
Β 
Β 
Β 
Β 

Table of ContentsπŸ“š

Hello world with cargo🚒

What is cargo❓

Cargo is a Rust package manager. It is used to manage dependencies and build Rust projects.

Creating a new projectπŸ†•

We will create a new project called hello-world-cargo, to do this, we will use the following command.

ℹ️ the --bin parameter flags the project as an application, not a library.

$ cargo new hello-world-cargo --bin

> Created binary (application) `hello-world-cargo` package.

This command created a new folder πŸ“‚ hello-world-cargo in the current directory.

This folder contains a πŸ“„ Cargo.toml file, a πŸ“‚ src folder and a πŸ“„ main.rs file.

hello-world-cargo
β”œβ”€β”€ Cargo.toml
β”œβ”€β”€ .git
β”‚   └── ...
β”œβ”€β”€ .gitignore
└── src
    └── main.rs

It also initialized a git repository for the project.

The πŸ“‚ src folder contains the source code of the application, in it there already is a πŸ“„ main.rs file containing an hello world program.

// πŸ“„ main.rs
fn main() {
    println!("Hello, world πŸ‘‹");
}
File Description
πŸ“„ Cargo.toml The Cargo manifest file, this file contains all the dependencies and the application name.
πŸ“‚ src The source folder, this folder contains the source code of the application.
πŸ“„ main.rs The main file, this file contains the source code of the application.
πŸ“‚ .git The git folder, this folder contains all the git files, you can ignore this folder if you don't use git.
πŸ“„ .gitignore The git ignore file, this file contains all the files that should be ignored when committing.

Compiling and running a program with cargoπŸƒ

Just compiling

To compile the program, we will use the cargo build command.

# hello-world-cargo πŸ“‚
$ cargo build

This command will compile the program and create an executable file called πŸ“„ hello-world-cargo in the new πŸ“‚ target/debug folder.

# hello-world-cargo/target/debug πŸ“‚
$ ./hello-world-cargo
> Hello, world πŸ‘‹

Compiling and runningπŸƒ

To compile and run the program, we will use the cargo run command.

# hello-world-cargo πŸ“‚
$ cargo run
...
> Hello, world πŸ‘‹


Home 🏠 - Next Section ⏭️


Course created by SkwalExe and inspired by Dcode