Rust

A short intro

With Pokémons, of course.

Disclaimers

I might not be able to answer all the questions.

I've been studying Rust for ~ 3 months, so I don't know much stuff.

Accepting feedback and suggestions!

Many Pokémons and GIFs!

(not even considering the stuff I don't know that exists!) - @ramalhoorg

Hi!

  • Computer Engineer
  • Programming
  • Electronics
  • Math <3 <3
  • Physics
  • Lego
  • Pokémon
  • Meetups
  • Animals
  • Coffee
  • GIFs

How could I make a talk about language features without being boring?

New language=> new Pokémon version

Pokémon: Rust version

  • Being developed for ~ 8 yeas [at least the idea] (source: https://www.youtube.com/watch?v=_-fweBvtifA ) 
  • ~ 2 years when it assumed the desired format and main goals
  • Mozilla

C/C++

Ruby/JS

Haskell/FP

C/C++

Ruby/JS

Haskell/FP

C/C++ - don't want GC

Ruby/JS -Nice language with compiler support

Haskell/FP - interesting type system

Starter

Starter

Cargo

Compiles, links and organises project dependencies in a single place

cargo new pokemon --bin

Source: http://doc.crates.io/guide.html

Starter

"hello world"

cargo run

variable bindings

fn main() {
    let party_size = 6;
}
fn main() {
    let party_size = 6;
    party_size = 5;

}

src/main.rs:3:5: 3:19 error: re-assignment of immutable variable `party_size` [E0384]

rustc --explain E0384

variable bindings

fn main() {
    let party_size = 6;
}
fn main() {
    let mut party_size = 6;
    party_size = 5;

}

It's super effective :)

variable bindings

let party_size: i32 = 6;
let party_size: i32;

TL;DR

  • Reminds some C style
  • You don't have to explicitly declare the type (but it's possible)
  • Be careful with immutability

Level up!

fn example(x: int) -> int

-> return type

( ) parameters are optional

fn level_up(level: i32) {
    println!("Level up {}", level + 1);
}
fn level_up(level) {
    println!("Level up {}", level + 1);
}
fn level_up_with_rare_candy(level: i32) -> i32 {
    level + 1
}
fn level_up_with_rare_candy(level: i32) -> i32 {
    level + 1;
}

Starter

"hello world"

Expressions vs statements

Expressions

  • Do return a value

Statements

  • Do NOT return a value
  • x +1;
fn use_potion(hp: i32) -> i32 {
    hp + 20
}

let current_hp = use_potion;

Function Pointers

let healed_hp = current_hp(5);

Rust Primitive Types

+ level up

ifs and loops

(Sp Def ==Safety)

Grass is a scope to capture Pokémons

let pokemons = vec![1, 2, 3, 4, 5, 6];
fn foo() {
}

But not in a battle!

You cannot capture your rival's Pokémon. You can throw the Pokéball, however.

let pokemons = vec![1, 2, 3, 4, 5, 6];
let pokemons_rival = pokemons;
println!("Capturei {}", pokemons[0]);

Wrong! One Pokémon, two trainers! That's wrong.

You can clone the Pokémon ( ͡° ͜ʖ ͡°)

Or **borrow** it

let pokemons = vec![1, 2, 3];
let pokemons_extras = vec![4, 5, 6];

let pokemon_party = forma_party(&v1, &v2);

&mut

let mut attack = 5;
{
    let new_attack = &mut attack;
    *new_attack += 1;
}
println!("{}", attack);

Prints 6

Starter

"hello world"

To be continued... :)

References and special thanks

  • Florian Gilcher - https://speakerdeck.com/skade/rust-is-the-only-thing-thats-left 
  • Video - https://www.youtube.com/watch?v=_-fweBvtifA (@steveklabnik)
  • Rust Docs - https://doc.rust-lang.org
  • @lafp (GIFs)
  • Rust by example - https://github.com/rust-lang/rust-by-example
  • Twitter Reviews

@Argorak

  • Hoenn Map with city names - http://depot.tigrisoft.com/games/rubysapp/images/hoennmap.jpg
  • Gym leaders Sprites! - http://bulbapedia.bulbagarden.net/wiki/Hoenn_League

Thank you :)

Questions?

 

hannelita@gmail.com

@hannelita

Rust (and Pokémons) - English version

By Hanneli Tavante (hannelita)

Rust (and Pokémons) - English version

  • 4,164