Rust is a general-purpose programming language that emphasizes performance, type safety, concurrency, and memory safety.
Rust supports multiple programming paradigms. It was influenced by ideas from functional programming, including immutability, higher-order functions, algebraic data types, and pattern matching. It also supports object-oriented programming via structs, enums, traits, and methods. Rust enforces memory safety (i.e., that all references point to valid memory) without a conventional garbage collector; instead, memory safety errors and data races are prevented by the "borrow checker", which tracks the object lifetime of references at compile time.
Software developer Graydon Hoare created Rust in 2006 while working at Mozilla, which officially sponsored the project in 2009. The first stable release, Rust 1.0, was published in May 2015. The project has been sponsored by the Rust Foundation since February 2021.
Rust has been adopted by many software projects, especially web services and system software. It has been studied academically and has a growing community of developers.
History 2006–2009: Early years
In 2006, Rust began as a personal project by Mozilla employee Graydon Hoare. According to MIT Technology Review, he started the project due to his frustration with a broken elevator in his apartment building whose software had crashed, and named the language after the fungi of the same name that is "over-engineered for survival". Between 2006 and 2009, Rust was not publicized to others at Mozilla and was written in Hoare's free time. Hoare began speaking about the language around 2009 after a small group at Mozilla became interested.
Early contributors have agreed that the language was based primarily on existing ideas. Hoare cited languages from the 1970s, 1980s, and 1990s as influences — including CLU, BETA, Mesa, NIL, Erlang, Newsqueak, Napier, Hermes, Sather, Alef, and Limbo. He described the language as "technology from the past come to save the future from itself." Early contributor Manish Goregaokar similarly described it as based on "mostly decades-old research."
The first compiler was written in about 38,000 lines of OCaml. It supported a number of features no longer present today, including explicit object-oriented programming via an keyword and a typestate analysis system tracking variable state such as going from uninitialized to initialized.
2009–2012: Mozilla sponsorship In 2009, Mozilla officially sponsored the project. Brendan Eich and other executives, intrigued by the possibility of using Rust for a safe web browser engine, placed engineers on the project including Patrick Walton, Niko Matsakis, Felix Klock, and Manish Goregaokar. A conference room taken by the project developers was dubbed "the nerd cave," with a sign placed outside the door.
Work shifted from the OCaml compiler to a self-hosting compiler (i.e., written in Rust) targeting LLVM. The ownership system was in place by 2010. The Rust logo was developed in 2011 based on a bicycle chainring. The early 2010s witnessed increasing involvement from full-time engineers at Mozilla and open source contributors.
On January 20, 2012, Rust 0.1 became the first public release for Windows, Linux, and MacOS. 2012–2015: Evolution The following years were marked by substantial changes to the Rust type system. Memory management through the ownership system was gradually consolidated and expanded; by 2013, the garbage collector was rarely used, and was removed. Also removed were typestates, the keyword, various specialized pointer types, and syntax support for channels.
According to Steve Klabnik, the language was influenced during this period by developers coming from C++ (e.g., low-level performance of features), scripting languages (e.g., Cargo and package management), and functional programming (e.g., the type system).
In 2013, Graydon Hoare stepped down from Rust. After Hoare's departure, it evolved organically under a federated governance structure, with a "core team" of initially six people, and around 30-40 developers total across various other teams. In March 2014, a Request for Comments (RFC) process for new language features was added. By 2016, the core team would grow to nine people with over 1600 RFCs.
Development focused on finalizing features for version 1.0 (which would begin providing backward compatibility). According to Andrew Binstock writing for Dr. Dobb's Journal in January 2014, while Rust was "widely viewed as a remarkably elegant language", adoption slowed because it radically changed from version to version.
On May 15, 2015, Rust 1.0 became the first stable release. One year later, the compiler had accumulated at least 1,400 contributors, and there were at least 5,000 third-party libraries published on the package management website Crates.io.
2015–2020: Servo and early adoption
The development of the Servo browser engine continued in parallel with Rust, funded by Mozilla and Samsung. New features in Rust were tested out by the Servo team, and new features in Servo were used to give feedback back to the Rust team. The first version of Servo was released in 2016. The Firefox web browser shipped with Rust code as of 2016 (version 45), but components of Servo did not appear in Firefox until September 2017 (version 57) as part of the Gecko and Quantum projects.
In the years following 1.0, improvements were made to the toolchain ecosystem including Rustfmt, integrated development environment (IDE) support, and a regular compiler testing and release cycle. Rust's community gained a code of conduct and an IRC chat for discussion.
The earliest known adoption outside of Mozilla was by individual projects at Samsung, Facebook (now Meta Platforms), Dropbox, and Tilde, Inc., the company behind ember.js. Amazon Web Services followed in 2020. Engineers cited performance, lack of a garbage collector, safety, and developer experience as reasons for the adoption. Amazon developers cited a 2017 research finding that Rust code was more energy efficient compared to similar Java code.
2020–present: Mozilla layoffs and Rust Foundation In August 2020, Mozilla laid off 250 of its 1,000 employees as part of a corporate restructuring during the COVID-19 pandemic. The Servo team was disbanded. The event raised concerns about the future of Rust. The Rust Core Team acknowledged the impact of the layoffs and announced plans for an independent foundation. Its first goal would be to own and take financial responsibility for trademarks and domain names.
On February 8, 2021, the Rust Foundation was formed by founding companies Amazon Web Services, Google, Huawei, Microsoft, and Mozilla. The foundation would support developers financially through grants and server funding. In an April 6, 2021 blog post, Google announced support for Rust within the Android Open Source Project. Facebook (Meta Platforms) joined the foundation in April 2021, followed by ARM (Arm Holdings) in November.
On November 22, 2021, the Moderation Team, responsible for enforcing the community code of conduct, resigned "in protest of the Core Team placing themselves unaccountable to anyone but themselves". In May 2022, the Rust leadership council published a response to the incident.
The Rust Foundation posted a draft for a new trademark policy on April 6, 2023 that resulted in widespread negative reactions. The trademark policy included rules for how the Rust logo and name could be used.
In June 2026, OpenAI joined the Rust Foundation.
Syntax and features
Rust's syntax is similar to that of C and C++, although many of its features were influenced by functional programming languages such as OCaml. Hoare has described Rust as targeted at frustrated C++ developers.
Hello World program Below is a "Hello, World!" program in Rust. The keyword denotes a function, and the macro (see ) prints the message to standard output. Statements in Rust are separated by semicolons. fn main() { println!("Hello, World!"); }
Variables Variables in Rust are defined through the keyword. The example below assigns a value to the variable with name of type and outputs its value; the type annotation can be omitted.
fn main() { let foo: i32 = 10; println!("The value of foo is {foo}"); }
Variables are immutable by default, unless the keyword is added. The following example uses , which denotes the start of a comment.
fn main() { // This code would not compile without adding "mut". let mut foo = 10; println!("The value of foo is {foo}"); foo = 20; println!("The value of foo is {foo}"); }
Multiple expressions can define multiple variables with the same name, known as variable shadowing. Variable shadowing allows transforming variables without having to name the variables differently. The example below declares a new variable with the same name that is double the original value:
fn main() { let foo = 10; // This will output "The value of foo is 10" println!("The value of foo is {foo}"); let foo = foo * 2; // This will output "The value of foo is 20" println!("The value of foo is {foo}"); }
Variable shadowing is also possible for values of different types. For example, going from a string to its length:
fn main() { let letters = "abc"; let letters = letters.len(); }
Block expressions and control flow A block expression is delimited by curly brackets. When the last expression inside a block does not end with a semicolon, the block evaluates to the value of that trailing expression:
fn main() { let x = { println!("this is inside the block"); 1 + 2
println!("1 + 2 = {x}"); }
Trailing expressions of function bodies are used as the return value:
fn add_two(x: i32) -> i32 { x + 2 }
expressions An conditional expression executes code based on whether the given value is . can be used for when the value evaluates to , and can be used for combining multiple expressions.
fn main() { let x = 10; if x > 5 { println!("value is greater than five");
if x % 7 == 0 { println!("value is divisible by 7"); } else if x % 5 == 0 { println!("value is divisible by 5"); } else { println!("value is not divisible by 7 or 5");
and blocks can evaluate to a value, which can then be assigned to a variable:
fn main() { let x = 10; let new_x = if x % 2 == 0 { x / 2 } else { 3 * x + 1 }; println!("{new_x}"); }
loops while can be used to repeat a block of code while a condition is met.
fn main() { // Iterate over all integers from 4 to 10 let mut value = 4; while value <= 10 { println!("value = {value}"); value += 1;
loops and iterators For loops in Rust loop over elements of a collection. expressions work over any iterator type.
fn main() { // Using `for` with range syntax for the same functionality as above // The syntax 4..=10 means the range from 4 to 10, up to and including 10. for value in 4..=10 { println!("value = {value}");
In the above code, is a value of type that implements the trait. The code within the curly braces is applied to each element returned by the iterator.
Iterators can be combined with functions over iterators like , , and . For example, the following adds up all numbers between 1 and 100 that are multiples of 3:
(1..=100).filter(|x| x % 3 == 0).sum()
and statements More generally, the keyword allows repeating a portion of code until a occurs. may optionally exit the loop with a value. In the case of nested loops, labels denoted by can be used to break an outer loop rather than the innermost loop.
fn main() { let value = 456; let mut x = 1; let y = loop { x *= 10; if x > value { break x / 10;
println!("largest power of ten that is smaller than or equal to value: {y}");
let mut up = 1; 'outer: loop { let mut down = 120; loop { if up > 100 { break 'outer;
if down < 4 { break;
down /= 2; up += 1; println!("up: {up}, down: {down}");
up *= 2;
Pattern matching