0% found this document useful (0 votes)
77 views2 pages

Rust Installation and Cargo Guide

Rust can be installed using `curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh`. The basic "Hello, World" program prints "Hello, World!" and can be compiled with `rustc main.rs` and run with `./main`. Cargo is Rust's build system and package manager that can create and build projects with `cargo new` and `cargo build`. Cargo projects contain a Cargo.toml file and src directory with code.

Uploaded by

Marina Atoyants
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views2 pages

Rust Installation and Cargo Guide

Rust can be installed using `curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh`. The basic "Hello, World" program prints "Hello, World!" and can be compiled with `rustc main.rs` and run with `./main`. Cargo is Rust's build system and package manager that can create and build projects with `cargo new` and `cargo build`. Cargo projects contain a Cargo.toml file and src directory with code.

Uploaded by

Marina Atoyants
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

# Getting Started

## Installation
- install rust `curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh`
(this also installs Cargo)
- install linker `xcode-select --install`

once Rust is installed, here are the available commands:


- `rustup update`
- `rustc --version`
- `rustup doc` - for local documentation

## Hello World

```rust
fn main() {
println!("Hello, world!");
}
```

- create file with extension `.rs`


- compile `rustc main.rs`
- this creates the executable file
- execute `./main`

## Cargo - build system and package manager


Cargo documentation: https://doc.rust-lang.org/cargo/

For more complex projects instead of using `rustc` use Cargo.

- install cargo
- use `cargo --version` if cargo was not installed
- create project with cargo
- `cargo new hello_cargo`
- this generates
- `Cargo.toml`
```rust
[package] - this is a headline
name = "hello_cargo"
version = "0.1.0"
edition = "2021"

[dependencies] - this is a headline


```
- `src` directory with a `main.rs` file inside
- inits git repo and creates `.gitignore`

### Building and Running Cargo Project

- `cargo build`
- `cargo run` or `./target/debug/hello_cargo`
- the result is stored in `target/debug` directory
- `cargo check` - compiles, but doesn't create an executable
- faster than build
- `cargo build --release` - for release
- creates executable with optimizations to run faster, but build and
compilation is long
- the result is stored in `target/release` directory

You might also like