Watch the Rust in 100 Seconds Video.
Article: What is Rust, and why is it so popular?
Rust is blazingly fast and memory-efficient: with no runtime or garbage collector, it can power performance-critical services, run on embedded devices, and easily integrate with other languages.
Rust’s rich type system and ownership model guarantee memory-safety and thread-safety — enabling you to eliminate many classes of bugs at compile-time.
Rust has great documentation, a friendly compiler with useful error messages, and top-notch tooling — an integrated package manager and build tool, smart multi-editor support with auto-completion and type inspections, an auto-formatter, and more.
"My biggest compliment to Rust is that it's boring, and this is an amazing compliment."
– Chris Dickinson, Engineer at npm, Inc
- Rust developers are known as "Rustaceans"
- Firefox, Dropbox, and Cloudflare use Rust!
- Rust is installed and managed by a tool called rustup
- Rust has a 6-week rapid release process and supports a great number of platforms, so there are many builds of Rust available at any time
Official site: rust-lang.org
Github: github.com/rust-lang
Code formatting: github.com/rust-lang/rustfmt
Crates: crates.io
curl https://sh.rustup.rs -sSf | sh
Follow the installation steps: forge.rust-lang.org/infra/other-installation-methods
In the Rust development environment, all tools are installed to the ~/.cargo/bin
directory, and this is where you will find the Rust toolchain, including rustc, cargo, and rustup.
Note:
Is customary for Rust developers to include this directory in their PATH environment variable. During installation rustup will attempt to configure the PATH. Because of differences between platforms, command shells, and bugs in rustup, the modifications to PATH may not take effect until the terminal is restarted, the user is logged out, or it may not succeed at all
- Restart your terminal and/or restart your computer
-or-
- Add Rust to PATH manually:
source $HOME/.cargo/env
- Add to your bash/zsh profile:
export PATH="$HOME/.cargo/bin:$PATH"
rustup update
rustup self uninstall
rustc --version
# rustc x.y.z (abcabcabc yyyy-mm-dd)
# If this fails, check your $PATH configuration
Cargo is a package manager that is equivalent to npm or pub, and comes built in with Rust.
- Create a new project:
cargo new project_name # Scaffold a new project
cd project_name # Open the project folder
code . # Open VS Code (or text editor of choice)
project_name
├── Cargo.toml
├── .gitignore
└── src
└── main.rs
Equivalent to pubspec.yaml in Dart/Flutter or package.json in JS/TS
[package]
name = "project_name"
version = "0.1.0"
edition = "2018"
[dependencies]
# Dependencies (crates) go here
Equivalent to index.js, main.dart, etc.
// Main application
fn main() {
// Print to console
println!("Hello, world!");
}
Builds update the file structure accordingly:
project_name
...
├── Cargo.lock
└── target
├── debug
└── release
cargo build
cargo build --release
Builds with optimizations for client delivery
cargo run
Compiling rust_in_100 v0.1.0 (/Users/klutch/Desktop/FireshipRust/rust_in_100)
Finished dev [unoptimized + debuginfo] target(s) in 4.52s
Running `target/debug/rust_in_100`
Hello, world!
cargo check # Verify that it compiles without building