Rust LogoInstallation and Hello World

Rust is a modern systems programming language known for its speed, memory safety, and concurrency. Before diving into its powerful features, the first step is to get it installed on your system and write your first program. Rust officially supports Linux, macOS, and Windows.

1. Installing Rust with `rustup`
The recommended way to install Rust is through `rustup`, a toolchain installer for Rust. `rustup` manages multiple Rust versions and associated tools, making it easy to keep your Rust installation up to date.

* On Linux and macOS:
Open your terminal and run the following command:
```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```
This script downloads `rustup` and installs the latest stable version of Rust. During the installation, you'll be prompted to choose an installation option. The default `1) Proceed with installation (default)` is usually the best choice.
After the installation completes, you might need to restart your shell or source your shell's profile (e.g., `source $HOME/.cargo/env`) to add Cargo's `bin` directory to your `PATH` environment variable.

* On Windows:
Download the `rustup-init.exe` installer from the official Rust website: [https://www.rust-lang.org/tools/install](https://www.rust-lang.org/tools/install).
Run the executable and follow the on-screen instructions. For the best experience, it's recommended to install the Microsoft C++ Build Tools when prompted, as Rust relies on a C linker. You can download these separately from Visual Studio's website if you don't already have them.

2. Verifying the Installation
Once `rustup` has finished, you can verify that Rust and its package manager, Cargo, are correctly installed by opening a new terminal or command prompt and running:
```bash
rustc --version
cargo --version
```
You should see output similar to `rustc 1.xx.x (abcde 2023-01-01)` and `cargo 1.xx.x (abcde 2023-01-01)`, indicating the installed versions.

3. Creating a New Project with Cargo
Cargo is Rust's build system and package manager. It handles tasks like creating new projects, building code, downloading dependencies, and running tests. For our first program, we'll use Cargo to create a new project.

Open your terminal and navigate to a directory where you want to store your project, then run:
```bash
cargo new hello_rust
```
This command creates a new directory named `hello_rust` with the following structure:
```
hello_rust/
├── Cargo.toml
└── src/
└── main.rs
```

* `Cargo.toml`: This is the manifest file for your project. It contains metadata about your project, dependencies, and how to build it.
* `src/main.rs`: This file contains the actual Rust source code for your application. For binary projects (executables), Cargo expects the entry point to be `src/main.rs`.

4. The "Hello World" Code
Cargo automatically generates a basic "Hello World" program for you in `src/main.rs`.
If you open `src/main.rs`, you will see:
```rust
fn main() {
println!("Hello, world!");
}
```
* `fn main()`: This defines a function named `main`. In Rust, `main` is the special function that serves as the entry point of every executable program.
* `println!("Hello, world!");`: This is a macro call. `println!` prints text to the console. The `!` indicates that it's a macro, not a regular function. The string `"Hello, world!"` is the argument passed to the macro. The line ends with a semicolon, as is typical for statements in Rust.

5. Compiling and Running Your Program
Navigate into your new project directory:
```bash
cd hello_rust
```

Now, you can compile and run your program using Cargo:
* Run (build and execute):
```bash
cargo run
```
This command compiles your code (if it hasn't been compiled yet or if changes have been made) and then executes the resulting binary. You should see `Hello, world!` printed to your terminal.

* Build (compile only):
```bash
cargo build
```
This command compiles your project and places the executable in the `target/debug/` directory. You can then run the executable directly, for example, `./target/debug/hello_rust` on Linux/macOS or `.\target\debug\hello_rust.exe` on Windows.
`cargo build --release` compiles with optimizations, producing a faster but larger executable in `target/release/`.

Congratulations! You've successfully installed Rust, created your first project, and run your "Hello, world!" program. This sets the foundation for exploring more advanced Rust concepts.

Example Code

// This is the main function, the entry point of the program.
fn main() {
    // The 'println!' macro prints text to the console.
    // The '!' denotes that it's a macro, not a regular function.
    println!("Hello, world!"); // Prints "Hello, world!" followed by a newline.
}