Over a million developers have joined DZone.

Mozilla is Developing a Language Called "Rust"

DZone 's Guide to

Mozilla is Developing a Language Called "Rust"

· ·
Free Resource
Along with web language champions such as Dave Herman and Brendan Eich, Mozilla's Graydon Hoare is developing a new programming language with an interesting mix of features.  The language is called " Rust", and although it's still in preliminary stages, it has an exciting list of features such as control over memory layout, structural typing, massive concurrency, and the ability to define complex invariants that hold over data structures.

It's difficult to make too many pre-judgements about the language at this stage.  The developers "really really don't want to be spending time on syntax discussions presently."  However, to placate the masses, the developers have posted a small sample testing tuple-outputs on iterators

iter pairs() -> tup(int,int) {
let int i = 0;
let int j = 0;
while (i < 10) {
put tup(i, j);
i += 1;
j += i;
fn main() {
let int i = 10;
let int j = 0;
for each (tup(int,int) p in pairs()) {
log p._0;
log p._1;
check (p._0 + 10 == i);
i += 1;
j = p._1;
check(j == 45);

So here is a brief overview of the features:

Safety oriented:

  • Memory safe. No null pointers, wild pointers, etc. Automatic storage management.
  • Mutability control. Immutable by default. No shared mutable state across tasks.
  • Dynamic execution safety: task failure / unwinding, trapping, logging. RAII / dtors.
  • Typestate system: ability to define complex invariants that hold over data structures.

Concurrency and efficiency oriented:

  • Explicit memory control. Layout and allocation control. Interior / value types.
  • Very lightweight tasks (coroutines). Cheap to spawn thousands-to-millions.
  • Stack iterators (effectively lambda-blocks w/o heap allocation).
  • Static, native compilation. Emits ELF / PE / Mach-o files.
  • Direct and simple interface to C code (switch stacks and call, ~8 insns).

Practicality oriented:

  • Multi-paradigm. pure-functional, concurrent-actor, imperative-procedural, OO.
  • First class functions with bindings.
  • Structurally-typed objects (no nominal types or type hierarchy).
  • Multi-platform. Developed on Windows, Linux, OSX.
  • UTF8 strings, assortment of machine-level types.
  • Works with existing native toolchains. GDB / Valgrind / Shark / etc.
  • Practical rule-breaking: can break safety rules, if explicit about where and how.

The Mozilla developers have done a good job of answering many of the questions from interested developers and programming language researchers.  Here are a few of the many questions that the Mozilla developers answer in an FAQ:

  • How do you get away with “no null pointers”?
  • Why is failure unwinding non-recoverable within a task? Why not try to “catch exceptions”?
  • Why don’t local functions or objects capture their dynamic environment? What’s with bind?
  • Why aren’t modules and values type-parametric?
  • Why aren’t channels synchronous?
  • Can Rust code call C code?  Or vice versa?
  • How do Rust’s task stacks work?
  • Why can’t stateful objects have destructors? Why only immutable ones?

You can see the discussion on Rust over at Lambda the Ultimate, where Dave Herman and Brendan Eich answer some questions and debate with commenters.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}