Enum Example - Rust Typing CST Test
Loading…
Enum Example — Rust Code
Demonstrates enums with associated data and pattern matching.
enum Message {
Quit,
Move { x: i32, y: i32 },
Write(String),
}
fn process(msg: Message) {
match msg {
Message::Quit => println!("Quit message"),
Message::Move { x, y } => println!("Move to ({}, {})", x, y),
Message::Write(text) => println!("Text: {}", text),
}
}
fn main() {
process(Message::Move { x: 10, y: 20 });
process(Message::Write(String::from("Hello")));
}Rust Language Guide
A modern, memory-safe, high-performance systems programming language focused on safety, concurrency, and zero-cost abstractions, designed to replace C/C++ in critical software.
Primary Use Cases
- ▸Systems programming
- ▸WebAssembly applications
- ▸Cloud-native backends
- ▸Blockchain and cryptographic systems
- ▸Embedded systems
- ▸Game engines
- ▸High-performance CLI tools
Notable Features
- ▸Memory safety without garbage collection
- ▸Ownership and borrowing system
- ▸Zero-cost abstractions
- ▸Powerful package manager (Cargo)
- ▸Pattern matching and algebraic data types
- ▸Fearless concurrency
Origin & Creator
Created by Graydon Hoare at Mozilla Research, first public release in 2010, and stable 1.0 released in 2015. Originated as a personal project, later backed by Mozilla. Evolved through Rust 2015, 2018, and 2021 editions, adding async/await, improved ergonomics, better tooling, Cargo, and a richer standard library.
Industrial Note
Highly adopted in cloud infrastructure, operating system components, cryptography, blockchain systems, safety-critical systems, and WebAssembly. Used by Microsoft, Amazon, Google, Cloudflare, and Meta for secure and high-performance services.