Rust (programming language) facts for kids
![]() |
|
Paradigms |
|
---|---|
Developer | The Rust Team |
First appeared | January 19, 2012 |
Stable release | |
Typing discipline |
|
Implementation language | OCaml (2006–2011) Rust (2012–present) |
Platform | Cross-platform |
OS | Cross-platform |
License | MIT, Apache 2.0 |
Filename extensions | .rs , .rlib |
Influenced by | |
Influenced | |
|
Rust is a powerful programming language that helps computer programs run very fast and safely. It's designed to prevent common errors, especially those related to how a computer uses its memory. Unlike some other languages, Rust doesn't need a "garbage collector" to clean up memory. Instead, it uses a special system called the "borrow checker" that checks for memory safety issues while the program is being built.
Rust can be used for many different kinds of programming. It takes ideas from functional programming, which focuses on using functions and keeping data unchanged. It also supports object-oriented programming, which uses "objects" to organize code.
A software developer named Graydon Hoare started Rust as a personal project in 2006. He was working at Mozilla Research at the time. Mozilla officially supported the project starting in 2009. The first stable version of Rust, called Rust 1.0, came out in May 2015. Later, in February 2021, several companies joined Mozilla to create the #Rust Foundation to help support Rust's future. In December 2022, Rust made history by becoming one of the first languages, besides C and assembly, to be used in developing the Linux kernel, which is the core of the Linux operating system.
Rust is becoming popular for many software projects, especially for web services (like websites and apps that run online) and system software (programs that control a computer's hardware). Many developers are learning and using Rust.
Contents
- How Rust Programming Language Started
- How Rust Code Works
- Your First Rust Program: "Hello, World!"
- Using Variables in Rust
- Code Blocks and How Programs Flow
- Matching Patterns in Rust
- Data Types in Rust
- Ownership and References
- Custom Data Types
- Pointers in Rust
- Polymorphism: Code That Works with Many Types
- Keeping Memory Safe
- How Rust Manages Memory
- Using `unsafe` Code
- Macros: Code That Writes Code
- Connecting Rust with C and C++
- Rust's Tools and Community
- How Rust Performs
- Where Rust is Used
- Rust in Research
- Rust Community
- See also
How Rust Programming Language Started
Early Days of Rust (2006–2009)
Rust began as a side project by Graydon Hoare, who worked at Mozilla. He started it in 2006 because he was frustrated with a broken elevator. Hoare named Rust after a type of fungus that is "over-engineered for survival," meaning it's built to last.
For the first few years, Rust was a personal hobby for Hoare. He worked on it in his free time. Around 2009, a small group at Mozilla became interested in his project. Hoare believed in using good ideas from older programming languages rather than always trying to invent new ones. He mentioned languages like CLU (from 1974) and Erlang (from 1987) as inspirations. He said that "many older languages [are] better than new ones."
In its early days, the Rust compiler (the program that turns code into something a computer can understand) was written using another language called OCaml.
Mozilla's Support for Rust (2009–2012)
In 2009, Mozilla officially started supporting the Rust project. Leaders like Brendan Eich saw the potential for Rust to create a safer web browser engine. They assigned engineers to work on the project full-time. The room where these developers worked was even called "the nerd cave."
During this time, the Rust compiler was rewritten in Rust itself. This is called "self-hosting." The special "ownership system" of Rust, which helps manage memory safely, was also put in place by 2010. The Rust logo, which looks like a bicycle chainring, was designed in 2011.
The first public version, Rust 0.1, was released on January 20, 2012, for Windows, Linux, and macOS. More and more volunteers from around the world started helping with Rust. Mozilla continued to employ many engineers to work on Rust for years.
Rust's Growth and Changes (2012–2015)
From 2012 to 2015, Rust went through big changes. The "typestate system" was removed, and other features were made simpler. The "garbage collector," which automatically cleans up memory, was also removed. Instead, Rust focused on its unique "ownership system" to prevent memory problems. By 2013, the garbage collector was rarely used, so the team decided to remove it.
Rust's development was influenced by different types of programmers. People who liked C++ helped make it fast. Those who liked scripting languages helped with tools like Cargo (for managing packages). And those who liked functional programming helped with the type system.
Graydon Hoare stepped down from leading Rust in 2013. This allowed the language to grow with a "core team" of leaders and many other developers. They also started a "Request for Comments (RFC)" process in 2014, where people could suggest new features for the language.
Even though Rust was seen as a "remarkably elegant language," its adoption was slow at first because it changed a lot between versions. The developers focused on making the language stable and ready for its 1.0 release.
Six years after Mozilla started supporting it, Rust 1.0 was released on May 15, 2015. A year later, over 1,400 people had helped with the Rust compiler. More than 5,000 third-party libraries (reusable code packages) were available on Crates.io, Rust's package management website.
Early Use and Growth (2015–2020)
Mozilla and Samsung worked together to develop the Servo browser engine using Rust. The teams for Rust and Servo worked closely. New features in Rust were tested by the Servo team, and their feedback helped improve Rust. Servo's first version came out in 2016. Parts of Servo were later included in the Firefox web browser starting in 2017.
Rust also improved its tools during these years. Tools like Rustfmt (for formatting code) and better integrated development environment (IDE) support were added. The community also created a code of conduct to ensure a friendly environment.
Some of the first companies to use Rust outside of Mozilla included Samsung, Facebook, and Dropbox. Later, Amazon Web Services (AWS) started using it in 2020. Engineers chose Rust because it was fast, safe, and enjoyable to work with. Amazon developers even found that Rust code used less energy than similar code written in Java and C++.
Mozilla Changes and the Rust Foundation (2020–Present)
In August 2020, Mozilla had to lay off many employees. This caused worries about the future of Rust. The Rust Core Team quickly announced plans to create a Rust foundation. The main goal was for the foundation to take ownership of Rust's trademarks and website names.
On February 8, 2021, the #Rust Foundation was officially formed. Five big companies were founding members: Amazon Web Services, Google, Huawei, Microsoft, and Mozilla. The foundation started offering grants to programmers working on important Rust features. In April 2021, Google announced that it would support using Rust in the Android Open Source Project as an alternative to C/C++.
In November 2021, the Moderation Team, which helped enforce the community's code of conduct, resigned due to disagreements with the Core Team. In response, the Rust Core Team and the Rust Foundation made changes to how the project was governed in May 2022.
In April 2023, the Rust Foundation proposed new rules for using the Rust logo and name. This caused some negative reactions from Rust users.
On February 26, 2024, the U.S. White House released a report encouraging software developers to use "memory-safe" languages like C#, Go, Java, Ruby, Swift, and Rust, instead of C and C++. This report has made more people interested in Rust.
How Rust Code Works
Rust's code looks a bit like C and C++. However, many of its features are inspired by functional programming languages like OCaml. Rust is designed to help C++ developers who want more safety, control over memory, and better handling of multiple tasks at once. Rust ensures memory safety, type safety, and prevents "data races" (when different parts of a program try to change the same data at the same time).
Your First Rust Program: "Hello, World!"
This is a classic first program that just prints a message.
fn main() {
println!("Hello, World!");
}
In this code:
- The
fn
keyword means you are defining a function. main
is the main function where your program starts.println!
is a special command (called a macro) that prints text to the screen.- Statements in Rust usually end with a semicolon (`;`).
Using Variables in Rust
Variables are like containers that hold information. In Rust, you use the let
keyword to create them.
fn main() {
let foo = 10;
println!("The value of foo is {foo}");
}
By default, variables in Rust are immutable, meaning their value cannot be changed after you set it. If you want to change a variable's value, you need to add the mut
keyword.
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}");
}
The `//` in the code means the rest of the line is a comment and is ignored by the computer.
You can also declare a new variable with the same name, which is called variable shadowing. This lets you transform a variable's value without needing a new name.
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}");
}
Code Blocks and How Programs Flow
A "block expression" is a section of code inside curly brackets (`{}`). If the last line in a block doesn't end with a semicolon, the block will give back that value.
fn main() {
let x = {
println!("this is inside the block");
1 + 2
};
println!("1 + 2 = {x}");
}
This is also how functions return values:
fn add_two(x: i32) -> i32 {
x + 2
}
Using `if` Statements
The if
statement runs code only if a certain condition is
. You can use true
else
for what happens if the condition is
, and false
else if
for more conditions.
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");
}
}
`if` and `else` blocks can also give back a value that you can store in a variable:
fn main() {
let x = 10;
let new_x = if x % 2 == 0 { x / 2 } else { 3 * x + 1 };
println!("{new_x}");
}
Repeating Code with `while` Loops
A `while` loop keeps running a block of code as long as a condition is true.
fn main() {
// Iterate over all integers from 4 to 10
let mut value = 4;
while value <= 10 {
println!("value = {value}");
value += 1;
}
}
Repeating Code with `for` Loops
For loops in Rust are used to go through each item in a collection.
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}");
}
}
The code inside the curly braces runs for each item. You can also combine `for` loops with functions like `map` (to change items) or `filter` (to pick certain items).
Matching Patterns in Rust
The match
and if let
statements help you check for different patterns in your data. For example, `match` can be used to double a number if it exists, or return zero if it doesn't.
fn double(x: Option<u64>) -> u64 {
match x {
Some(y) => y * 2,
None => 0,
}
}
You can write the same thing using if let
:
fn double(x: Option<u64>) -> u64 {
if let Some(y) = x {
y * 2
} else {
0
}
}
Data Types in Rust
Rust is a strongly and statically typed language. This means that the type of every variable must be known when the program is built. If you try to put a value of one type into a variable meant for another, you'll get an error. Rust can often guess the type of a variable if you don't specify it.
The default type for whole numbers (integers) is i32
, and for numbers with decimals (floating points) it's f64
.
Basic Data Types
- Integers: Named by their signedness (if they can be negative) and how many bits they use. For example,
i32
is a 32-bit signed integer, and
is an 8-bit unsigned integer.u8
isize
andusize
change size based on your computer's architecture (e.g., 32-bit or 64-bit). - Booleans:
bool
can be eithertrue
orfalse
. - Characters:
char
takes up 32 bits and represents a single Unicode codepoint (like a letter, number, or symbol). - Floating-point numbers:
f32
for single precision floats andf64
for double precision floats.
Combined Data Types
- Tuples: Fixed-size lists that can hold values of different types.
- Arrays: Fixed-size lists where all values must be of the same type.
let tuple: (u32, bool) = (3, true);
let array: [i8; 5] = [1, 2, 3, 4, 5];
let value = tuple.1; // true
let value = array[2]; // 3
Ownership and References
Rust has a unique "ownership system" that makes sure memory is used safely without a garbage collector.
- Every value in Rust has one "owner" (a variable).
- When a value is assigned or passed to a function, its ownership can "move."
- Values can also be "borrowed" temporarily by other functions.
This system prevents "dangling pointers" (pointers that point to memory that's no longer valid).
fn print_string(s: String) {
println!("{}", s);
}
fn main() {
let s = String::from("Hello, World");
print_string(s); // s consumed by print_string
// s has been moved, so cannot be used any more
// another print_string(s); would result in a compile error
}
In the example above, `print_string` takes ownership of `s`. If you want to just let a function look at a value without taking ownership, you use a "reference" with `&`.
fn print_string(s: &String) {
println!("{}", s);
}
fn main() {
let s = String::from("Hello, World");
print_string(&s); // s borrowed by print_string
print_string(&s); // s has not been consumed; we can call the function many times
}
When a value's owner goes out of scope (meaning the variable is no longer needed), the value is "dropped," and its memory is automatically cleaned up. This helps manage resources like files or network connections.
Lifetimes of Data
"Lifetimes" refer to how long a reference to a piece of data is valid. Rust's compiler checks these lifetimes to make sure you don't try to use data that no longer exists.
fn main() {
let x = 5; // ------------------+- Lifetime 'a
// |
let r = &x; // -+-- Lifetime 'b |
// | |
println!("r: {}", r); // | |
// | |
// -+ |
} // ------------------+
In this example, `x` lives longer than `r`, so it's safe. But if `x` had a shorter lifetime, Rust would give an error to prevent problems.
fn main() {
let r; // ------------------+- Lifetime 'a
// |
{ // |
let x = 5; // -+-- Lifetime 'b |
r = &x; // ERROR: x does | |
} // not live long -| |
// enough |
println!("r: {}", r); // |
} // ------------------+
This system helps Rust prevent common memory errors.
Custom Data Types
You can create your own data types using struct
or enum
.
struct
is like a blueprint for a record that groups several related values together.enum
allows a variable to take on different forms or "variants." This is similar to "algebraic data types" in functional programming.
Both `structs` and `enums` can hold different types of data inside them.
The impl
keyword lets you define "methods" (functions that belong to a specific type) for your custom types. This is similar to how "classes" work in other programming languages.
Standard Library Tools
Rust's standard library provides many useful data types and tools. These include common structures like `Vec` (a resizable list), `Option` (for values that might be missing), and `HashMap` (for storing key-value pairs).
Rust uses `Option` to handle values that might not be there. You can use `if let` or `match` to check if a value is present.
fn main() {
let name1: Option<&str> = None;
// In this case, nothing will be printed out
if let Some(name) = name1 {
println!("{name}");
}
let name2: Option<&str> = Some("Matthew");
// In this case, the word "Matthew" will be printed out
if let Some(name) = name2 {
println!("{name}");
}
}
Pointers in Rust
Rust has different types of "pointers" (variables that store memory addresses).
- The `&` and
&mut
reference types are guaranteed to be safe and point to valid memory. - The "raw pointer" types
*const
and*mut
don't have these safety guarantees. They might be null or invalid. You can only use them inside anunsafe
block, which tells Rust you are taking responsibility for safety.
Polymorphism: Code That Works with Many Types
Rust supports bounded parametric polymorphism. This means you can write code that works with different types, as long as those types follow certain rules defined by "traits."
- Traits define shared behaviors that different types can implement.
- Generic functions can work with any type that implements a specific trait.
// zero is a generic function with one type parameter, Num
fn zero<Num: Zero>() -> Num {
Num::zero()
}
fn main() {
let a: u32 = zero();
let b: f32 = zero();
assert!(a.is_zero() && b.is_zero());
}
This allows you to write flexible code that doesn't need to be repeated for every single data type.
Trait Objects for Dynamic Behavior
While generic functions are very fast because Rust figures out the exact types when it builds the program, Rust also has "trait objects." These allow for "dynamic dispatch," where the program decides which version of a function to use while it's running. This is useful when you have a list of different types that all share a common behavior.
use std::fmt::Display;
let v: Vec<Box<dyn Display>> = vec![
Box::new(3),
Box::new(5.0),
Box::new("hi"),
];
for x in v {
println!("{x}");
}
Here, `dyn Display` means "any type that can be displayed." If an item in the list can't be displayed, you'll get an error when you build the program.
Keeping Memory Safe
Rust is designed to be very memory safe. It prevents common errors like:
- Null pointers (pointers that don't point to anything).
- Dangling pointers (pointers that point to memory that's no longer valid).
- Data races (when different parts of a program try to change the same data at the same time).
Rust makes sure that all data values are properly set up before they are used.
How Rust Manages Memory
Rust doesn't use garbage collection, which is a system that automatically cleans up memory in many other languages. Instead, Rust manages memory using its ownership system. This means Rust has very low "overhead" (extra work the computer has to do).
- Values are usually stored on the "stack" (a fast memory area).
- Any "dynamic allocation" (when memory is asked for during the program's run) must be clearly stated.
Rust's reference types (`&` and `&mut`) are checked when the program is built to make sure they are safe. Rust also makes a clear difference between "shared, immutable references" (`&T`, meaning many parts of the program can look at the data, but not change it) and "unique, mutable references" (`&mut T`, meaning only one part of the program can look at and change the data).
Using `unsafe` Code
Sometimes, programmers need to do very low-level things that Rust's safety checks normally prevent. For these rare cases, you can use
blocks. Inside an `unsafe` block, you can do things like:unsafe
- Work directly with raw pointers.
- Call code written in other languages.
- Access memory in special ways.
When you use `unsafe` code, you are telling Rust that you, the programmer, are responsible for making sure the code is safe and doesn't cause problems. `unsafe` code is sometimes needed for very complex data structures, like certain types of lists.
Macros: Code That Writes Code
Macros are like special instructions that generate or change Rust code. They help reduce repetition in your programs. There are two main types:
Declarative Macros
These macros use patterns to decide how to expand. They are defined with `macro_rules!`.
macro_rules! sum {
( $initial:expr $(, $expr:expr )* $(,)? ) => {
$initial $(+ $expr)*
}
}
fn main() {
let x = sum!(1, 2, 3);
println!("{x}"); // prints 6
}
Procedural Macros
These are more complex Rust functions that run and change the code before it's built. They are more flexible but harder to write. They come in three forms: function-like, derive, and attribute macros.
Connecting Rust with C and C++
Rust can work with code written in C and C++. You use the extern
keyword to do this. This is useful for using existing libraries or parts of programs written in C or C++.
#[unsafe(no_mangle)]
pub extern "C" fn exported_from_rust(x: i32) -> i32 { x + 1 }
unsafe extern "C" {
fn imported_into_rust(x: i32) -> i32;
}
Tools like `bindgen` and `cxx` can help create the necessary connections between Rust and C/C++ code.
Rust's Tools and Community
The Rust ecosystem includes its compiler, standard library, and other tools for software development. The `rustup` tool helps you install and manage these components.
The Rust Compiler
The Rust compiler, called
, turns your Rust code into a low-level language that computers understand. It uses another tool called LLVM to make the code run faster and then turns it into a final program.rustc
Cargo: Rust's Package Manager
Cargo is Rust's main tool for building projects and managing "packages" (reusable code libraries). It downloads, builds, and helps you share these packages, which are called "crates." Crates are stored in an official online registry called crates.io.
Rustfmt: Code Formatter
Rustfmt is a tool that automatically formats your Rust code. It makes sure that spacing and indentation (how much lines are pushed in) follow a common style. This makes code easier to read and understand for everyone.
Clippy: Code Helper
Clippy is Rust's built-in "linting" tool. It checks your code for common mistakes, suggests ways to improve performance, and makes it more readable. As of 2024, Clippy has over 700 rules to help you write better Rust code.
Rust's Version System
After Rust 1.0 was released, new features are first developed in "nightly" versions, which are released daily. Every six weeks, changes from nightly versions move to a "beta" version, and then to a new "stable" version.
Every few years, a new "edition" of Rust is released. Editions allow for some small changes that might break older code, but they also bring important new features. Programs written in different editions can still work together. Tools are available to help you update your code to a new edition.
IDE Support
rust-analyzer is a set of tools that helps integrated development environments (IDEs) and text editors understand your Rust projects. This allows for helpful features like autocomplete (guessing what you're typing) and showing compilation errors as you write code.
How Rust Performs
Rust is often faster than other memory-safe languages because it doesn't use garbage collection. Most of Rust's safety checks don't slow down the program while it's running. For example, checking if you're trying to access an array outside its boundaries is done by default, which can sometimes affect performance.
Many of Rust's features are "zero-cost abstractions." This means they are optimized away when the program is built, so they don't add any extra work when the program runs. Rust's ownership system allows for "zero-copy" operations, which are very efficient for tasks like reading and processing data.
Since Rust uses LLVM, any improvements to LLVM also make Rust faster. Rust can also rearrange how data is stored in memory to make it more efficient.
Where Rust is Used

Rust is used in many different types of software. Parts of the Servo browser engine, which was funded by Mozilla and Samsung, are now in the Gecko browser engine that powers Firefox. In January 2023, Google announced that it would support using Rust libraries in its Chromium web browser.
Rust is also used in the "backend" (the server side) of many large web services.
- OpenDNS, a service owned by Cisco, uses Rust.
- Amazon Web Services (AWS) uses Rust in parts of its services that need to be very fast. AWS also made Firecracker, a virtualization tool written in Rust, available to everyone.
- Microsoft Azure IoT Edge, which runs Azure services on IoT devices, uses Rust. Microsoft also uses Rust with WebAssembly and Kubernetes.
- Cloudflare, a company that helps websites run faster, built a new web proxy called Pingora using Rust.
- The npm package manager uses Rust for its authentication service.

In operating systems:
- The Rust for Linux project added initial support for Rust code to the Linux kernel in late 2022. This project is actively adding more Rust code to the kernel.
- Android developers started rewriting parts of their system in Rust in 2021.
- Microsoft has rewritten parts of Windows in Rust.
- Rust is used in new operating systems like Redox and Fuchsia.
- It's also used for command-line tools and operating system components like stratisd and COSMIC.
In web development, Deno, a secure runtime for JavaScript and TypeScript, is built with Rust. Other projects include Ruffle, an open-source SWF emulator, and Polkadot, a blockchain platform.
Discord, a messaging company, rewrote parts of its system in Rust in 2020 to make it faster. In the same year, Dropbox announced that its file synchronization system was rewritten in Rust. Facebook used Rust to redesign its system for managing internal source code.
In the 2024 Stack Overflow Developer Survey, Rust was named the "most admired programming language" for the ninth year in a row. This means many developers who use it want to keep using it. Also, many developers who don't use Rust are interested in learning it.
The DARPA agency has a project called TRACTOR (Translating All C to Rust) that aims to automatically translate C code into Rust.
Rust in Research
Researchers have studied Rust's safety and performance in the field of programming language theory.
Rust has also been used in other research areas. For example, a journal article used Rust to simulate multi-planet systems. Another article in Nature shared stories of bioinformaticians (scientists who use computers to study biology) using Rust. Both articles found that Rust is good for performance and safety, but noted that it can be challenging to learn at first.
Rust Community

The Rust community is known for being very welcoming to new people. Many Rust users call themselves "Rustaceans" (like the word crustacean) and have an orange crab named Ferris as their unofficial mascot. The community has a code of conduct that sets expectations for how members should interact.
According to GitHub, the Rust community grew by 50.5% in 2022, making it one of the fastest-growing programming communities.
Rust Foundation
![]() |
|
Formation | February 8, 2021 |
---|---|
Founders |
|
Type | Nonprofit organization |
Location | |
Shane Miller | |
Rebecca Rumbul |
The Rust Foundation is a non-profit group in the United States. Its main goals are to support the Rust technical project as a legal entity and to help manage its trademarks and online resources.
It was created on February 8, 2021, by five founding companies: Amazon Web Services, Huawei, Google, Microsoft, and Mozilla. Shane Miller is the chairperson of the foundation's board. Rebecca Rumbul became its Executive Director and CEO in late 2021.
How Rust is Governed
The Rust project is organized into "teams" that are responsible for different parts of its development. For example, the compiler team works on the compiler, and the language team designs new features. As of July 2024, there are six main teams. Representatives from these teams form the Leadership Council, which oversees the entire Rust project.
See also
In Spanish: Rust (lenguaje de programación) para niños
- Comparison of programming languages
- History of programming languages
- List of programming languages
- List of programming languages by type