AnatomyOf

Anatomy of a Rust file

example.rs
1use std::fmt;
2
3struct Greeting {
4 text: String,
5}
6
7impl Greeting {
8 // Borrows self, not the borrow checker's patience
9 fn shout(&self) -> String {
10 format!("{}!", self.text)
11 }
12}
13
14fn main() {
15 let g = Greeting { text: String::from("hello") };
16 println!("{}", g.shout()); // it compiled, ship it
17}
Rust is a systems programming language focused on safety, speed, and concurrency, with a strong emphasis on memory safety without a garbage collector.