Rust: A Friendly Introduction

Session Audio

Excerpt

Conventional wisdom says that writing high-performance code means working without the safety net of credible compile-time safety checks. Mozilla Research (a community of researchers, engineers, and volunteers) is trying to prove that conventional wisdom wrong by building Rust, a new systems programming language. Rust takes advantage of well-understood programming language technology to combine aggressive compile-time error checking with the high degree of direct control over the machine necessary to write efficient systems programs. By way of examples, I'll teach you how to use Rust to write fast and trustworthy code.

Description

When writing systems-level applications like operating systems, device drivers, and Web browser engines, many things can go wrong. Null pointers, buffer overflows, and memory leaks all occur in C and C++-based applications in the wild, and can all cause serious security vulnerabilities. C and C++ compilers and tools are at best only partially able to detect these problems during development. While memory-safe languages such as Haskell and Scala solve these problems, historically, systems programmers have not found these languages acceptable for meeting their performance goals. Rust, a new open-source language being stewarded by Mozilla, aims to make memory safety bugs a thing of the past without sacrificing performance. Rust supports large-scale programming and its needs for reliability, efficient use of space and time, and concurrency.

In this tutorial talk, I will show you how to write fast code in Rust with the help of a compiler that detects many potential bugs at compile time. I will start by showing you how to write simple prototypes in a subset of Rust that uses garbage collection. Then, I will refine these examples to use Rust’s “borrowed pointers”. Using borrowed pointers eliminates the overhead of garbage collection because the compiler can determine these pointers’ lifetimes at compile time. I will show you how to manage memory in Rust in ways that are just as efficient as they would be in a C++ program but enjoy stronger compile-time correctness checking than C++ compilers provide. As I’ll explain, this style of coding requires more thought during development because you have to be explicit about the relationships between data structures in memory, but it pays off in the long term by eliminating dangling pointers and memory leaks, without incurring unwanted memory management overhead.

All the examples I’ll show will be based on real applications, potentially drawn from an audio decoder, an NES game emulator, and a prototype Web browser engine (Servo – https://github.com/mozilla/servo – under development at Mozilla). All examples will be adapted from open-source programs that are freely available on Github. I’ll assume that audience members are comfortable programming in at least one language and have at least a passing familiarity with either C or C++.

Speaking experience

I have spoken at the Haskell Implementors' Workshop (2009) and at the Portland Functional Programming Study Group (pdxfunc), as well as at Portland State University when i was a student there. This will be my first time speaking outside Mozilla about Rust, so the talk will be entirely new.

Speaker

Biography

I’ve been programming in Haskell for 14 years. After a 3-year sojourn at Mozilla working on the Rust team, I returned to functional programming as a software engineer at AlephCloud Systems. I studied computer science at Portland State University; the University of California, Berkeley; and Wellesley College. I’ve been contributing to open-source projects for ten years. When I’m not writing code, I like to write about social and political issues, ride my bicycle, and play with my cats.

Sessions

Conventional wisdom says that writing high-performance code means working without the safety net of credible compile-time safety checks. Mozilla Research (a community of researchers, engineers, and volunteers) is trying to prove that conventional wisdom wrong by building Rust, a new systems programming language. Rust takes advantage of well-understood programming language technology to combine aggressive compile-time error checking with the high degree of direct control over the machine necessary to write efficient systems programs. By way of examples, I’ll teach you how to use Rust to write fast and trustworthy code.