001 - Your First Rust Program
How to Create and Run a Rust File
If you’re coming from Python, you’re used to python script.py. In Rust, source code is compiled first, then executed.
Why this matters for Python developers
- Rust has a build step, which catches many issues before runtime.
cargois the standard workflow (project creation, build, run, test).- Learning this flow early makes every later lesson smoother.
Learning goals
By the end of this lesson, you should be able to:
- Install and verify the Rust toolchain.
- Create and run a Rust project with
cargo. - Understand when to use
cargovsrustc.
Concepts in 5 minutes
rustup: toolchain manager.cargo: Rust package manager and build tool.rustc: low-level compiler command (useful, but not daily default).
Step 1: Install and verify Rust
Install via rustup and verify:
rustc --version
cargo --version
Step 2: Cargo-first workflow (recommended)
cargo new hello_rust
cd hello_rust
cargo run
This creates project files and runs the default src/main.rs.
Expected output includes:
Hello, world!
Step 3: Edit and rerun
Replace src/main.rs with:
fn main() {
println!("Hello, Rust!");
}
Run again:
cargo run
Optional: single-file compile with rustc
Useful for quick experiments:
rustc main.rs
Run binary:
./main # Linux/macOS
main.exe # Windows (cmd/powershell)
Common first-run issues
cargonot found: reopen terminal after install, or ensure Rust is in PATH.- Permission issues on Unix: check shell profile setup from rustup installer.
- Wrong folder:
cargo runmust be inside a project withCargo.toml.
Quick practice
- Change output to
"Hello from Python to Rust!"and run. - Add a second
println!line and run again.
Recap
Use cargo as the default workflow. Reach for rustc only when you specifically want single-file compilation.
Next lesson: core syntax and structure.
Join the Journey Ahead!
If you're eager to continue this learning journey and stay updated with the latest insights, consider subscribing. By joining our mailing list, you'll receive notifications about new articles, tips, and resources to help you seamlessly pick up Rust by leveraging your Python skills.
Other articles in the series
- 000 - Learning Rust as a Pythonista: A Suggested Path
- 002 - Basic Syntax and Structure
- 003 - Ownership, Borrowing, and Lifetimes
- 004 - Error Handling
- 005 - Structs and Enums
- 006 - Iterators and Closures
- 007 - Traits vs Duck Typing and Protocols
- 008 - Concurrency in Rust for Python Developers
- 009 - Async Concurrency with Tokio
- 010 - Pattern Matching in Rust
- 011 - Macros in Rust