Nate Mara
2016-03-30
Rust is a systems programming language that combines the speed of C/C++ with the 'safety' of garbage-collected languages like Python & Java. It is being developed by Mozilla for their new browser engine, Servo.
Rust has several features that make it a good choice for a project:
This has a few important implications:
Consider this C++ code:
template <class T>
bool foo(T x, T y) {
return x == y;
}
Equivalent Rust:
fn foo<T: PartialEq>(x: T, y: T) -> bool {
x == y;
}
let x = 100;
x += 10; // compiler error
let mut x = 100;
x += 10;
The type of variables does not explicitly have to be defined when defining variables.
let mut hashes = HashSet::new();
hashes.insert("00f013675328fac432");
enum Suit {
Hearts,
Clubs,
Diamonds,
Spades,
}
match card.suit {
Hearts => println!("Hearts"),
Clubs => println!("Clubs"),
Spades => println!("Spades"),
} // will not compile because Diamonds case was not dealt with
Only used when interfacing with C
match deck.draw_card() {
Some(card) => println!("You picked {}", card),
None => println!("No more cards left!"),
}
Five rules of ownership