0% found this document useful (0 votes)
21 views1 page

Rust Programming Language Overview

Uploaded by

warholabarbarino
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views1 page

Rust Programming Language Overview

Uploaded by

warholabarbarino
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

The Rust Language

Nicholas Matsakis Felix S. Klock II


Mozilla Research Mozilla Research
nmatsakis@[Link] pnkfelix@[Link]

1. ABSTRACT teed to be free of memory errors (dangling pointers, double


Rust is a new programming language for developing reli- frees) as well as data races.
able and efficient systems. It is designed to support concur- To control aliasing and ensure type soundness, Rust in-
rency and parallelism in building applications and libraries corporates a notion of ownership into its type system. The
that take full advantage of modern hardware. Rust’s static unique owner of an object can hand that ownership off to
type system is safe1 and expressive and provides strong guar- new owner; but the owner may also hand off borrowed refer-
antees about isolation, concurrency, and memory safety. ences to (or into) the object. These so-called borrows obey
Rust also offers a clear performance model, making it eas- lexical scope, ensuring that when the original reference goes
ier to predict and reason about program efficiency. One im- out of scope, there will not be any outstanding borrowed ref-
portant way it accomplishes this is by allowing fine-grained erences to the object (otherwise known as “dangling point-
control over memory representations, with direct support ers”). This also implies that when the owner goes out of
for stack allocation and contiguous record storage. The lan- scope or is otherwise deallocated, the referenced object can
guage balances such controls with the absolute requirement be deallocated at the same time. Rust leverages the lat-
for safety: Rust’s type system and runtime guarantee the ter property by adding support for user-defined destructors,
absence of data races, buffer overflows, stack overflows, and enabling RAII2 patterns as popularized by C++.
accesses to uninitialized or deallocated memory. There are two flavors of borrows: mutable and immutable.
Mutable references have a uniqueness property: There can
be at most one active mutable borrow of a given piece of
Categories and Subject Descriptors state (the owner itself is not allowed to mutate the object
D.3.0 [E.2]: Programming Language Standards for the duration of the mutable borrow, nor are any of the
inactive mutable borrows). Immutable references, on the
other hand, can be freely copied, and their referents can
Keywords be the source for new immutable borrows (subject to the
Rust, Systems programming, Memory management, Affine restriction that all borrows still respect the lexical scope of
type systems the object’s owner).
Rust functions can manipulate objects that are owned by
2. MEMORY MANIPULATION IN RUST local variables arbitrarily far up the control stack. Such
functions need to support operations like *ptr1 = *ptr2;
Rust is a new programming language targeting systems- (writing the dereferenced value of ptr2 into the memory
level applications. Like C++, Rust is designed to map di- referenced by ptr1), but must also respect the rules: such
rectly to hardware, giving users control over the running assignment statements must be prohibited from injecting
time and memory usage of their programs. This implies, for dangling pointers.
example, that all Rust types can be allocated on the stack A function that manipulates borrowed references needs
and that Rust never requires the use of a garbage collector to constrain its input parameters to ensure that executing
or other runtime. Unlike C++, however, Rust also offers the function body will not break the rules. Rust has an op-
strong safety guarantees: pure Rust programs are guaran- tional explicit syntax for describing the lifetime bounds asso-
1
Type soundness has not yet been formally proven for Rust, ciated with a reference. Lifetime bounds mix together with
but type soundness is an explicit design goal for the lan- lifetime-polymorphism (analogous to type-polymorphism) to
guage. provide functions the expressive power needed to manipulate
memory references, without breaking type safety.
Permission to make digital or hard copies of all or part of this work for personal or
classroom use is granted without fee provided that copies are not made or distributed
for profit or commercial advantage and that copies bear this notice and the full cita-
tion on the first page. Copyrights for components of this work owned by others than
ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or re-
publish, to post on servers or to redistribute to lists, requires prior specific permission
and/or a fee. Request permissions from permissions@[Link].
HILT 2014, October 18–21, 2014, Portland, OR, USA.
Copyright 2014 ACM 978-1-4503-3217-0/14/10 ...$15.00. 2
[Link] RAII: “Resource Acquisition Is Initialization”

103

You might also like