fn main() {
println!("Hello developer's day");
}
Most loved programming language since 2016
fn read_book(book: &Book) {
// gain non mutable access to `book`
// and give it back (borrow it)
}
fn sign_book(book: &mut Book) {
// gain exclusive mutable access to `book`
// and give it back (borrow it)
}
fn destroy_book(book: Book) {
// become the new owner of `book` (own it)
} // here book is destroyed
fn main() {
let dangling; // --------+- 'a
{ // |
let local = 42; // -+- 'b |
dangling = &local; // | |
} // -+ |
println!("{}", *dangling); // |
} // --------+
fn main() {
let dangling;
{
let local = 42;
dangling = &local;
}
println!("this is not fine: {}", *dangling);
}
// cpp
int main() {
int *dangling;
{
int local = 42;
dangling = &local;
}
std::cout << "this is not fine: "<< *dangling << std::endl;
return 0;
}
fn main() {
let dangling;
{
let local = 42;
dangling = &local;
}
println!("this is not fine: {}", *dangling);
}



fn sum_of_squares(input: &[i32]) -> i32 {
input
.iter() // <-- just change that!
.map(|&i| i * i)
.sum()
}
# Python
def sum_of_squares(input: List[int]) -> int:
return sum(map(lambda i: i * i, input))
use rayon::prelude::*;
fn sum_of_squares(input: &[i32]) -> i32 {
input
.par_iter() // <-- parallel iterator
.map(|&i| i * i)
.sum()
}
fn main() {
println!(
"sum of squares: {}",
sum_of_squares(vec![1, 2, 3, 4, 5, 6].as_slice())
)
}
Ferris: Rust unofficial mascot
animation by A. L. Palmer (Rust Fest Berlin 2016)