Table of Contents

Rust is supposedly a safe language, unlike C and its extensions.

Learn rust

Variables and types

  et a = 5u8;
  et b = 16u32;
  et c = a as u32 + b;
 

Printing to the screen

Conditionals and loops

  f a > b {
  println!("a gt b");
   else if b > a{
  println!("b gt a");
 
  et s = loop {
  x += 1;
  if x == 128 {
  	break "reached 128!";
  }
  ;
  rintln!("position: {}", s);
 

switch -> match

io::stdin().read_line(&mut n);
 
match n {
	5 => {
		println!("got 5");
	}
	// mutiple options
	10 | 15 | 20 => {
		println!("some multiple of 5");
	}
	// bind match to variable
	n @ 21..=100 => {
		println!("found him: {}", n);
	}
	// obligatory default match
	_ => {
		println!("too far gone");
	}
}

Functions

This seems a lot like math notation (function add defined over i32 * i32 with values in i32, f(x,y)=x+y;

fn add(x: i32, y: i32) -> i32 {
    return x + y;
    }
fn main() {
	let a = 5;
	let x = {
		let a = 10;
		let b = 20;
		a + b
	}
	// will print "a: 5 x: 30"
	// b no longer exists here
	println!("a: {} x: {}", a, x);
 
}

Methods

Methods are functions associated with a type.

Macros

Macros in rust are like functions but they end with a !.

See also