Introduction
Rust is a statically and strongly typed systems programming language designed for performance, reliability, and memory safety. Unlike C and C++, Rust achieves memory safety without a garbage collector by enforcing strict compile-time rules through its ownership and borrow-checker system. This makes Rust suitable for building operating systems, browser engines, game engines, embedded devices, and high-performance web services.
Cricket analogy: Rust's ownership and borrow-checker enforce safety at selection time, like a strict team-composition rule checked before the toss rather than a manager firing players mid-match (garbage collection); this discipline makes it suited for building the scoring engine of a stadium's entire broadcast system.
Syntax
fn main() {
println!("Hello, Rust!");
}Explanation
Every Rust program starts execution from the main function. The println! macro (note the exclamation mark, which indicates it is a macro rather than a regular function) prints text to standard output followed by a newline. Rust code is compiled ahead of time by rustc into a native binary, using LLVM as its backend, so there is no interpreter or virtual machine involved at runtime.
Cricket analogy: Every Rust program starts at main like every match starts with the toss; println!'s exclamation mark flags it as a macro (a pre-match ritual) rather than a regular function (in-game action), and rustc compiles the whole strategy ahead of time via LLVM into a "match-ready" binary, with no live umpire interpreter needed at runtime.
Example
fn main() {
let language = "Rust";
let year_stable = 2015;
println!("{} reached its 1.0 stable release in {}.", language, year_stable);
}Output
Rust reached its 1.0 stable release in 2015.Key Takeaways
- Rust is a systems programming language focused on safety, speed, and concurrency.
- Memory safety is enforced at compile time via ownership and borrowing, with no garbage collector.
- Rust programs are compiled ahead of time using rustc, with LLVM as the backend.
- The main function is the entry point of every Rust binary.
- Rust offers zero-cost abstractions, meaning high-level features don't add runtime overhead.
Practice what you learned
1. What is the primary way Rust achieves memory safety?
2. Which macro is commonly used to print text to the console in Rust?
3. What compiler backend does rustc use to generate native code?
4. Which of the following is NOT a typical Rust use case?
Was this page helpful?
You May Also Like
History and Evolution of Rust
A look at how Rust originated at Mozilla Research and evolved into an independently governed language.
Features of Rust
An overview of the core language features that make Rust safe, fast, and productive to use.
Setting Up a Rust Environment
Step-by-step guide to installing Rust with rustup and creating your first Cargo project.
Ownership in Rust
Rust's core memory-safety system where every value has exactly one owner and is dropped when that owner goes out of scope.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics