Skip to content

Instantly share code, notes, and snippets.

@booyaa
Last active September 20, 2017 12:52
Show Gist options
  • Save booyaa/eb1ce194d00ac1305c634cf612281bc5 to your computer and use it in GitHub Desktop.
Save booyaa/eb1ce194d00ac1305c634cf612281bc5 to your computer and use it in GitHub Desktop.
talks

Schedule

  • 6:30PM - We'll try to get the Skillsmatter AV team to do setup their laptop. It's the one they use specially for hangouts. One important thing I learnt from last time, is to have the webcam pointing at at the audience. Should help Niko get some audience feedback. We might be buggered if they need us to turn off the lights though. We'll also try to do a quick hangout test with Niko if possible.
  • 6:50PM - Intro - We need volunteers to help with Rust workshops for the Mozilla Festival Oct 27th-29th (there will be a paper to stick your email address on if interested). https://www.mozillafestival.org/
  • Niko Matsakis (Rust Core Team) - Compiler internals
    • Intro (if you want something to read off here's the bios (from skillsmatter and meetup pages))
    • Niko does his talk
    • 5-10 mins Q & A
  • 5 mins break
  • Amanieu d'Antras (member of Brussels Rust group) - Intrusive collections for Rust
    • Intro
    • Amanieu does his talk
    • 5-10 mins Q & A
  • David Harvey-Macaulay - three-rs: High-level 3D in Rust
    • Intro
    • David does his talk
    • 5-10 mins Q & A
  • Thank everyone, get them to go get drinks and return here to chat.

Speaker bios:

  • Nicholas (Niko) Matsakis is a senior researcher at Mozilla research and a member of the Rust core team. He has been working on Rust for nearly six years and did much of the initial work on its type system and other core features. Prior to working on Rust, he did his undergraduate studies at MIT and completed a PhD at ETH Zurich in 2011. He also spent several years at DataPower Technology, a startup since acquired by IBM, working on the JIT compiler and networking runtime.
  • Amanieu d'Antras obtained his PhD at the University of Manchester for this thesis titled "Low Overhead Binary Translation for ARM". He specializes in binary translation, which allows programs compiled for one architecture to be run on a different architecture. He maintains a few Rust libraries (intrusive-collections, parking_lot, thread_local) and has made several contributions to the Rust compiler and standard library.
  • David Harvey-Macaulay - pending

Intro

  • Rust and Friends (1) - Name
  • Introduction - Community related team. First port of call. Local meetup organiser. Tonight I’ll give you an intro and the tools, efficient.
  • What is Rust? - Graydon Hoare. 2010. Apple. But what is Rust?
  • rust-lang.org definition (4) - elevator pitch from site. Break it down.
    • Systems programming - application programming is biz/user requirements. websites and app store. sys is next tier down. expect to write device drivers/os/crypto.
    • Blazingly fast - how fast? translation service analogy. also fast because of memory management rather than gc. fast is subjective, so benchmarks benchmarks (7) - 5 toy programs from the benchmark game. pinch of salt. no sub for your own experiment. pidigits is 10,000 digits of pi.
    • Prevents segfaults - Or segmentation faults are where a program crashes with no error handling. C, mismanagement of memory access. Segfaults Borrow checker, memory allocation and it’s life time, if not happy won’t compile.
    • Guarantees thread safety - thread programming is tough in systems programming. two risks: dead locks and data race condition. Rayon.
  • Example code (10) - code fragments.
    • Iterators - partition boolean expression. tuple of true and false vector values. More on vectors later.
    • I/O - RW a file. Buffered read. ? unwrap an Optional value (don’t do nulls. Some or None). If we get None bubble error to stack. Lines method turns input into an iterator so we can loop.
    • Serialization - Let deserialise a string containing JSON data. Serde crate. Create type called Point. Our string contain JSON. from_str method and reference to string. Unwrap the optional. If there’s no value crash out.
  • Who’s using Rust in Production? - features that make Rust attractive to companies. Let’s see a list of co’s using Rust in Production.
    • Who’s using Rust in Production? GIF (12) - start gif, notable companies Mozilla, Chef, Dropbox
  • The Rust toolset - avoid “toolchain”. Tool set list (4 + debuggers)
    • rustup (14) - toolchain manager. version manager. switch between versions, channels and targets. cpu-manufacturer-os/binformat triple.
    • rustc - compiler, write simple code.
    • documentation - doc is key, even code in your libraries are compiled as part of the build.
    • cargo - not just the package manager. recall rustc can compile simple programs. build your api documentation. sub commands: cargo-edit and cargo-deb.
    • debugging - llvm and gnu compiler debugger. haven’t needed to use this, because i rely on unit tests. do appreciate this is not always possible in systems programming which is why you need a debugger.

Time check: 10mins

Demo Time!

  • prerecoded, not fast enough type and talk.
  • Used Docker so can see what demo looks like in Ubuntu 16:04 (Xenial) with dev tools.
  • GitHub Repo.

Demo: Install Rust (2 mins)

Reminder, this a base build with just the build tools.

As you can see no rustup.

Install via curl shell. Feel free to check the shell script before you run it manually, like you do with other installer where you elevate right?

The installer, if you pick the default you get the stable toolchain.

Download begins. Note: compiler, standard library, cargo and documentation.

Note toolchain and the target triple.

Since we’re going to use Rust now, let’s add it to the path (don’t normally need to do this).

Version check.

let’s give Rust a go by creating a binary project. We can do this using the bin switch. If you omit this you get a library project instead. Both give you a small bit of boiler plate.

And we’re done

Demo: Toolchain management

Stable (default) toolchain.

Install the latest version of nightly.

As before, we get the compiler, standard library, cargo and documentation.

Now have two toolchains.

How to switch between toolchains

Create project that only uses stable features.

Run.

Note the range is not inclusive in for loops. There’s a nightly feature to address this.

Incidentally this is how you enable features, they’re gated i.e. now enabled by default in nightly so you can use it to test your stable code against it.

Rustup - note stable is still default. So what do you think is going to happen when we run this code?

Let’s override the default for this project.

Tada!


Time check: 10mins

Wrap up (5 mins left)

  • Rust london user group (24) - meet monthly. two events. two startups. trivia.
  • Exercism and Rustlings
  • URLO - this is a common abbreviation. ask questions, help, talk till cows come home.
  • TWIR - news letter, changes to Rust, meet ups, calls for participation.
  • community.rs - even more.
  • Summary - give rust a go, lots of people in the industry. rustup to install and manage versions. cargo. RLS best code editing experiencing. URLO. TWIR. community website.
  • Thanks and then QR code
$ cat hello.rs
fn main() {
println!("Hello, World");
}
$ rustc hello.rs
$ ./hello
Hello, World
$
let path = "lines.txt";
let mut output = File::create(path)?;
write!(output, "Rust\n💖\nFun")?;
let input = File::open(path)?;
let buffered = BufReader::new(input);
for line in buffered.lines() {
println!("{}", line?);
}
let a = [1, 2, 3];
let (even, odd): (Vec<i32>, Vec<i32>) = a.into_iter()
.partition(|&n| n % 2 == 0);
assert_eq!(even, vec![2]);
assert_eq!(odd, vec![1, 3]);
/// Consumes an iterator, creating two collections from it.
///
/// The predicate passed to `partition()` can return `true`, or `false`.
/// `partition()` returns a pair, all of the elements for which it returned
/// `true`, and all of the elements for which it returned `false`.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// let a = [1, 2, 3];
///
/// let (even, odd): (Vec<i32>, Vec<i32>) = a.into_iter()
/// .partition(|&n| n % 2 == 0);
///
/// assert_eq!(even, vec![2]);
/// assert_eq!(odd, vec![1, 3]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn partition<B, F>(self, mut f: F) -> (B, B) where
Self: Sized,
B: Default + Extend<Self::Item>,
F: FnMut(&Self::Item) -> bool
{
let mut left: B = Default::default();
let mut right: B = Default::default();
for x in self {
if f(&x) {
left.extend(Some(x))
} else {
right.extend(Some(x))
}
}
#![feature(inclusive_range_syntax)]
fn main() {
for i in 1...10 {
print!("{} ", i);
}
// output: 1 2 3 4 5 6 7 8 9 10
}
// source: https://play.integer32.com/?gist=14a2cb4006efcd7a9819241c2304df7c&version=nightly
#[derive(Serialize, Deserialize, Debug)]
struct Point {
x: i32,
y: i32,
}
fn main() {
let s = r#"{
"x":1,
"y":2
}"#;
let d: Point =
serde_json::from_str(&s).unwrap();
println!("deserialized = {:?}", d);
}
// source: https://play.integer32.com/?gist=d3c45f05287a1b9254b7ba228f0598a7&version=stable
fn main() {
for i in 1..11 {
print!("{} ", i);
}
// output: 1 2 3 4 5 6 7 8 9 10
}
// source: https://play.integer32.com/?gist=764d794209dc00c50c70a6593643fb5b&version=stable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment