Skip to main content

Rust

Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/rust

In short

Rust is a compiled, statically typed systems language that provides memory safety without a garbage collector by checking ownership rules at compile time.

What is the Rust programming language?

Rust is a general-purpose systems programming language that started as a personal project of Graydon Hoare, was later sponsored by Mozilla, and reached version 1.0 in 2015. Today it is developed by the open-source Rust project with support from the independent Rust Foundation. Its goal is to offer the speed and low-level control of C and C++ while preventing whole classes of memory bugs.

Rust is statically and strongly typed, with extensive type inference. Its memory model is based on ownership: every value has exactly one owner, and the value is freed automatically when its owner goes out of scope. Other code can borrow a value through references, and the compiler's borrow checker enforces the rule that you can have either many readers or one writer at a time, never both. Rust also has no null and no exceptions; missing values use the Option type and recoverable errors use the Result type.

Rust is used for command-line tools, web servers, WebAssembly modules, embedded devices, browser components, and parts of operating systems, including drivers in the Linux kernel. The borrow checker works like a lending library: many people may read a book at the same time, or one person may check it out to write in it, but never both at once, and the library always knows when the book comes back.

A common confusion is how Rust achieves memory safety. Unlike Java or Go, it does not use a garbage collector at runtime; the compiler checks the ownership rules before the program ever runs, so there are no collection pauses. The trade-off is a steeper learning curve, since code that would compile in C may be rejected until ownership is clear. For low-level work the compiler can't verify, Rust offers clearly marked unsafe blocks.

Key takeaways

  • Rust compiles to native machine code with performance comparable to C and C++.
  • Ownership and borrowing rules give memory safety without a garbage collector.
  • The compiler prevents data races in safe code, making concurrency safer.
  • Errors are handled with Result and missing values with Option instead of exceptions and null.

Example

Ownership and borrowingrust
fn main() {
    let greeting = String::from("Hello");

    // Borrow the string with & so main keeps ownership
    print_twice(&greeting);

    let moved = greeting; // Ownership moves to the new variable
    // println!("{}", greeting); // Compile error: greeting was moved
    println!("{} still works", moved);
}

fn print_twice(text: &str) {
    println!("{text} {text}");
}

Readers ask

Why is Rust considered memory-safe?

The compiler checks ownership and borrowing rules before the program runs, which rules out common bugs such as use-after-free, double free, and data races in safe code. Low-level operations that can't be checked are limited to clearly marked unsafe blocks.

Is Rust hard to learn?

Rust has a reputation for a steep learning curve, mainly because of ownership and the borrow checker. Its compiler error messages are detailed and often suggest fixes, which helps newcomers.

Does Rust have a garbage collector?

No. Rust frees memory deterministically when a value's owner goes out of scope, so there are no garbage collection pauses.

Often compared

See also

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings