Installation and Cargo
Introduction
Rust is installed via rustup, which manages the compiler (rustc), the package manager and build tool (Cargo), and the standard library. There is no separate "Rust SDK" installer like .NET; rustup is the single entry point.
Installing Rust
- Visit https://rustup.rs or run:
Bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh - After installation,
rustc --versionandcargo --versionshould work in a new terminal.
Cargo: Build and Package Manager
Cargo is both the build system and the package manager for Rust. It plays a role similar to dotnet + NuGet in the C# world.
| C# | Rust |
|---|---|
dotnet new console | cargo new my_project |
dotnet run | cargo run |
dotnet build | cargo build |
dotnet test | cargo test |
.csproj + packages | Cargo.toml + crates |
In C#: A solution (.sln) references projects (.csproj). In Rust, a workspace (Cargo.toml with [workspace]) lists member crates; each crate has its own Cargo.toml. There is no separate "solution" file.
Creating a New Project
cargo new my_app
cd my_appThis creates:
Cargo.toml– package manifest (name, version, dependencies).src/main.rs– entry point (likeProgram.cswithMain).
In C#: Roughly like a single-project console app: one "project" with one main file.
Running and Building
cargo run # Build and run the binary
cargo build # Only build (output in target/debug/ or target/release/)
cargo build --release # Optimized buildIn C#: cargo run is like dotnet run; cargo build --release is like dotnet publish -c Release (without the publish step).
The Entry Point: main.rs
fn main() {
println!("Hello, world!");
}fn main()– Program entry point (no args in this form; usestd::env::args()for CLI args).println!– Macro (the!indicates a macro), similar toConsole.WriteLinein C#.
In C#: Equivalent to static void Main() and Console.WriteLine("Hello, world!");.
Key takeaway
Rust is installed via rustup; Cargo is the single tool for building, running, and testing. There is no separate solution file; workspaces list member crates. main.rs and println! are your first building blocks.