Skip to content
This repository was archived by the owner on Oct 1, 2018. It is now read-only.

Incorporate Mexico Rustbridge into slide decks #89

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
4 changes: 2 additions & 2 deletions presentations/intro-to-rust/custom.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
html, body {
font-family: "Open Sans", sans-serif;
font-family: 'Fira Sans', "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #333;
}

Expand Down Expand Up @@ -49,4 +49,4 @@ h5 {
.pull-right {
float: right;
width: 47%;
}
}
5 changes: 3 additions & 2 deletions presentations/intro-to-rust/globe.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
// Each entry: [name, lat, lon]
var city_data = [
["Berlin", "52.52", "13.41"],
["Pittsburgh", "40.44", "-79.99"]
["Pittsburgh", "40.44", "-79.99"],
["Mexico City", "19.432608", "-99.133209"],
];

var width = 960,
Expand Down Expand Up @@ -184,4 +185,4 @@
</script>


</body></html>
</body></html>
Binary file modified presentations/intro-to-rust/img/cratesio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions presentations/intro-to-rust/img/rust-logo-blk.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
171 changes: 151 additions & 20 deletions presentations/intro-to-rust/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class: middle, center

![ferris](img/ferris.gif)

# A Very Brief Intro to Rust

???
Expand All @@ -21,13 +22,13 @@
---
class: middle, center

## 2ND RUSTBRIDGE IN THE WORLD!
## 3RD RUSTBRIDGE IN THE WORLD!

<iframe src="globe.html" style="width: 100%; height: 100% ; border: none" />
<iframe src="globe.html" style="width: 90%; height: 90% ; border: none" />

???

* Welcome to the 2nd Rustbridge IN THE WORLD
* Welcome to the 3rd Rustbridge IN THE WORLD

---
class: middle, center
Expand All @@ -36,26 +37,68 @@

???

* This curriculum is an experiment. It's disorganized and untested.
* This curriculum is an experiment. It's mildly disorganized and semi-tested.
* Please take notes about what you liked, didn't like, wished we spent more or less time on, etc -- there will be a survey!

---
class: middle, left

## Overview

* Rust, Cargo, Setup
* What and why Rust?
* Rustup, Cargo, Setup
* Syntax + Concepts mostly the same as other languages
* Syntax + Concepts particular to Rust
* Further learning

???

* So anyway, lets get started. Here is our agenda.

---
class: middle, center

![firefox](img/firefox-512-noshadow.png)

???

* Rust came out of Mozilla Research
* 300 Million users
* Written in C++
* Mozilla decided that C++ was fundamentally unsafe.

---
class: middle, left

## What is Rust?
## Read after free

```c
Audio* audio = new Audio("sound.wav");

...

delete audio;

...

play(audio);
```

???

* Classic bug is called use-after-free.
* Addressed by garbage collection
* Problem with GC is performance

---
class: middle, center

<img src=img/rust-logo-blk.svg width=512>

---
class: middle, center

Rust is a systems programming language that runs blazingly fast, prevents
segfaults, and guarantees thread safety.
## Rust is a systems programming language that runs blazingly **fast**, **prevents segfaults**, and guarantees **thread safety**

???

Expand All @@ -67,6 +110,36 @@
---
class: middle, left

## What is Systems Programming?

* Programming without a Garbage Collector
* Operating Systems, Databases, Games
* Close to the Metal
* Pay-as-you-go, lightweight runtime, or no runtime

???

* Systems programming can mean many things to many people.
* One of the primary
* One way of thinking about it is programm

---
class: middle, left

## That doesn't to mean

* You need to be an expert programmer
* Pointers, malloc, and free
* Targeting Unix-only or Windows-only
* Old school tools like hand-crafted Makefiles

???

* Writing your entire language in a systems language

---
class: middle, left

## Rust Philosophy

* Favor explicit over implicit
Expand All @@ -88,6 +161,31 @@
- cool new stuff is still being added!
- experimental stuff starts nightly only

---
class: middle, center

## Setting up Rust with Rustup and Cargo

---
class: middle, left

## What is Rustup?

Rustup is the official Rust toolchain installer, and makes it easy to keep Rust up to date.
It supports all Rust platforms, including Windows.

1. `curl https://sh.rustup.rs -sSf | sh`
2. `rustup install stable`

If that did not work, try:

1. `source ~/.cargo/env`
2. `rustup install stable`

Or you can use one of the builtin installers:

https://www.rust-lang.org/en-US/other-installers.html

---
class: middle, left

Expand All @@ -97,6 +195,7 @@
* Build tool
* Test runner
* Documentation generator
* Package publisher

???

Expand Down Expand Up @@ -203,7 +302,7 @@
`rustup doc --std`

---
class: middle, left
class: middle, center

## Syntax + Concepts mostly the same as other languages

Expand All @@ -213,6 +312,7 @@
## Comments

* Double slash at the beginning of a line (`//`)
* Block quotes with `/*` and `*/`
* Try commenting out one of your lines printing!
* There are other kinds of comments but this is the most common

Expand All @@ -227,15 +327,15 @@
println!("Hi, {}! You are {} years old.", name, age);
```

* Try making more variables and printing them all out in one `println!`
Try making more variables and printing them all out in one `println!`

???

* `let`, variable name, single equals, value, semicolon.
* Crab pincers in println, then values that should fit in there

---
class: middle, left
class: left

## Experiment

Expand All @@ -252,6 +352,18 @@
* Have someone read the error message
* Whenever anyone gets an error message, we'll read it out loud and talk about it so everyone can learn!

--

```
error[E0384]: re-assignment of immutable variable `apples`
--> src/main.rs:3:5
|
2 | let apples = 100;
| ------ first assignment to `apples`
3 | apples += 50;
| ^^^^^^^^^^^^ re-assignment of immutable variable
```

---
class: middle, left

Expand Down Expand Up @@ -339,6 +451,7 @@
}
}
```

???

* Shorthand for numeric type annotation
Expand Down Expand Up @@ -379,7 +492,7 @@

## Arrays

Kinda like arrays in other languages, but worse.
Kinda like arrays in other languages.

```rust
let mut color = [255, 0, 255];
Expand Down Expand Up @@ -485,7 +598,7 @@

## Iterators

```
```rust
for i in (0..10).filter(|x| x % 2 == 0) {
println!("i = {}", i);
}
Expand Down Expand Up @@ -561,7 +674,7 @@
* Destructure to get values out

---
class: middle, left
class: middle, center

## Syntax + Concepts particular to Rust

Expand All @@ -577,7 +690,7 @@
```rust
enum Option<T> {
Some(T),
None
None,
}
```

Expand Down Expand Up @@ -613,7 +726,7 @@
```rust
let a = Some("Carol");

let name = a.expect("No name present");
let name = a.expect("A value is present");
println!("Name is {} bytes long", name.len());
```

Expand Down Expand Up @@ -724,15 +837,15 @@
---
class: middle, left

## `try!` macro to propagate errors up
## `?` to propagate errors up

* Can only be used in methods/functions that return `Result`!!!!
Can only be used in methods/functions that return `Result`!!!!

```rust
fn add_five_to_string(s: String) ->
Result<i32, std::num::ParseIntError> {

let ans = try!(s.parse::<i32>()) + 5;
let ans = s.parse::<i32>()? + 5;
Ok(ans)
}
```
Expand Down Expand Up @@ -802,6 +915,21 @@
---
class: middle, left

## A common problem

```rust
fn fizz(num: u32) -> String {
if num % 3 == 0 {
"Fizz".to_string() // <-- convert "Fizz" into a string
} else {
num.to_string()
}
}
```

---
class: middle, left

## Slices

* A view into some data
Expand Down Expand Up @@ -1008,7 +1136,10 @@
<script src="remark.js" type="text/javascript">
</script>
<script type="text/javascript">
var slideshow = remark.create();
var slideshow = remark.create({
highlightStyle: 'default',
highlightLines: true,
});
</script>
</body>
</html>
1 change: 1 addition & 0 deletions presentations/intro-to-rust/index.json

Large diffs are not rendered by default.