Rust Language
(In progress)

Jacob Kim
astyfx's blog
Published in
1 min readFeb 17, 2015
let x: i32 = 5;
let y = 6; // y: i32

Above is a style of variable declaration of Rust.

()

Above is the Unit, that is special type in Rust’s type system.
() is not valid value for a variable of type i32.
It’s only a valid value for variables of the type ().
Unique type of Rust.

&str

&str is read as a ‘string slice’

let (x: i32, y: i32) = (5, 6)

Tuple, let “destructures,” or “breaks up,” the tuple, and assigns the bits to three bindings.

struct Point { x: i32, y: i32 }

struct name is camelCase.

key: value

Above is rust’s variable syntax style.

struct Inches(i32);

let length = Inches(10);

let Inches(integer_length) = length;
println!("length is {} inches", integer_length);

Above called as newtype.

let x = 5;

match x {
1 => println!("one"),
2 => println!("two"),
3 => println!("three"),
4 => println!("four"),
5 => println!("five"),
_ => println!("something else"),
}

_ acts like a catch-all. (in other language, default)

::

Double colon means namespace.

ex)
enum Mouse {
Button,
Wheel
}

:: used in enum or library import like Mouse::Button, Mouse::Wheel.

Rust has two statements. Everything else is an expression.
  1. declaration statement
  2. expression statement ( purpose is to turn any expression into a statement )
for var in expression {
code
}

For loop in Rust.

while true { }->loop { }

while loop when true. in Rust just loop {}

--

--