Your First Rust Program
Let’s get you up and running with Rust in just a few minutes.Verify your installation
First, make sure Rust is properly installed:You should see version information for both the Rust compiler (
rustc) and the package manager (cargo).If you don’t have Rust installed yet, head over to the Installation page.
Write Hello World
Create a new file called This is a simple Rust program that prints “Hello, world!” to the console.
main.rs:Creating a Project with Cargo
Whilerustc is great for simple programs, most Rust developers use Cargo - Rust’s build tool and package manager.
Explore the project structure
Cargo.toml - The manifest file containing metadata and dependencies:src/main.rs - Your source code (already contains a “Hello, world!” program)
Essential Cargo Commands
Here are the most important Cargo commands you’ll use:cargo new
Create a new Cargo project
cargo build
Compile your project
cargo run
Build and run your project
cargo test
Run your project’s tests
cargo check
Check if your code compiles (faster than build)
cargo doc
Build documentation for your project
Adding Dependencies
Cargo makes it easy to use external libraries (called “crates” in Rust).Essential Tools
Rust comes with powerful tools to improve your development experience:rustfmt - Code Formatter
Automatically format your code to follow Rust style guidelines:Clippy - Linter
Catch common mistakes and improve your code:rust-analyzer - IDE Support
For the best development experience, install the rust-analyzer extension for your editor:- VS Code: Search for “rust-analyzer” in extensions
- IntelliJ/CLion: Rust plugin with rust-analyzer support
- Vim/Neovim: Use CoC or native LSP support
- Emacs: Use lsp-mode or eglot
rust-analyzer provides real-time error checking, code completion, inline documentation, and more.
Understanding Rust’s Type System
Here’s a quick example showing Rust’s powerful type system and ownership model:Next Steps
Now that you have Rust set up and running, here are some great resources to continue learning:The Rust Book
The official comprehensive guide to Rust
Rust by Example
Learn Rust through annotated example programs
Rustlings
Small exercises to get you used to reading and writing Rust
Standard Library Docs
Complete documentation for the Rust standard library
Getting Help
If you run into issues or have questions:- Check the official documentation
- Ask on the Rust Users Forum
- Join the Rust Discord or Zulip
- Search Stack Overflow with the
rusttag
Contributing to Rust
Interested in contributing to the Rust compiler itself?- Read the Contributing Guide
- Explore the rustc dev guide for compiler architecture
- Join the #new members Zulip stream
- Check the Standard Library Developers Guide
There are many ways to contribute to Rust beyond just writing code - documentation, testing, triaging issues, and helping others are all valuable contributions!