Rust is a systems programming language focused on safety, speed, and concurrency. It achieves memory safety without garbage collection, making it ideal for performance-critical applications.
📑 Table of Contents
Key Features
- Memory Safety: No null pointers or data races
- Zero-Cost Abstractions: High-level syntax, low-level speed
- Ownership System: Compile-time memory management
- Cargo: Integrated package manager and build tool
- Cross-Compilation: Build for multiple targets
Installation
Install Rust using rustup:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source ~/.cargo/env
rustc --version
Usage Examples
Rust programming examples:
use std::fs;
fn main() {
// File reading with error handling
let contents = fs::read_to_string("file.txt")
.expect("Failed to read file");
// Ownership and borrowing
let s1 = String::from("hello");
let len = calculate_length(&s1);
println!("Length of '{}' is {}", s1, len);
}
fn calculate_length(s: &String) -> usize {
s.len()
}
Benefits
Rust prevents common bugs at compile time while matching C/C++ performance. Its growing ecosystem makes it viable for web services, embedded systems, and CLI tools.
Was this article helpful?