Rust (programming language)

From HandWiki
Short description
Memory-safe programming language without garbage collection
A capitalised letter R set into a sprocket
The official Rust logo
ParadigmsMulti-paradigm: concurrent, functional, generic, imperative, structured
Designed byGraydon Hoare
DeveloperThe Rust Foundation
First appearedJuly 7, 2010; 11 years ago (2010-07-07)
Typing disciplineAffine, inferred, nominal, static, strong
Implementation languageRust
LicenseMIT or Apache 2.0[1]
Filename, .rlib
Influenced by

Rust is a multi-paradigm, high-level, general-purpose programming language designed for performance and safety, especially safe concurrency.[11][12] Rust is syntactically similar to C++,[13] but can guarantee memory safety by using a borrow checker to validate references.[14] Rust achieves memory safety without garbage collection, and reference counting is optional.[15][16]

Rust was originally designed by Graydon Hoare at Mozilla Research, with contributions from Dave Herman, Brendan Eich, and others.[17][18] The designers refined the language while writing the Servo experimental browser engine,[19] and the Rust compiler. It has gained increasing use in industry, and Microsoft has been experimenting with the language for secure and safety-critical software components.[20][21]

Rust has been voted the "most loved programming language" in the Stack Overflow Developer Survey every year since 2016, though only used by 7% of the respondents in the 2021 survey.[22]


An example of compiling a Rust program

The language grew out of a personal project begun in 2006 by Mozilla employee Graydon Hoare,[12] who stated that the project was possibly named after the rust family of fungi.[23] Mozilla began sponsoring the project in 2009[12] and announced it in 2010.[24][25] The same year, work shifted from the initial compiler (written in OCaml) to the LLVM-based self-hosting compiler written in Rust.[26] Named rustc, it successfully compiled itself in 2011.[27]

The first numbered pre-alpha release of the Rust compiler occurred in January 2012.[28] Rust 1.0, the first stable release, was released on May 15, 2015.[29][30] Following 1.0, stable point releases are delivered every six weeks, while features are developed in nightly Rust with daily releases, then tested with beta releases that last six weeks.[31][32] Every 2 to 3 years, a new Rust "Edition" is produced. This is to provide a easy reference point for changes due to the frequent nature of Rust's Train release schedule, as well as to provide a window to make breaking changes. Editions are largely compatible.[33]

Along with conventional static typing, before version 0.4, Rust also supported typestates. The typestate system modeled assertions before and after program statements, through use of a special check statement. Discrepancies could be discovered at compile time, rather than at runtime, as might be the case with assertions in C or C++ code. The typestate concept was not unique to Rust, as it was first introduced in the language NIL.[34] Typestates were removed because in practice they were little used,[35] though the same functionality can be achieved by leveraging Rust's move semantics.[36]

The style of the object system changed considerably within versions 0.2, 0.3 and 0.4 of Rust. Version 0.2 introduced classes for the first time, and version 0.3 added several features, including destructors and polymorphism through the use of interfaces. In Rust 0.4, traits were added as a means to provide inheritance; interfaces were unified with traits and removed as a separate feature. Classes were also removed and replaced by a combination of implementations and structured types.(citation?)

Starting in Rust 0.9 and ending in Rust 0.11, Rust had two built-in pointer types: ~ and @, simplifying the core memory model. It reimplemented those pointer types in the standard library as Box and (the now removed) Gc.

In January 2014, before the first stable release, Rust 1.0, the editor-in-chief of Dr. Dobb's, Andrew Binstock, commented on Rust's chances of becoming a competitor to C++ and to the other up-and-coming languages D, Go, and Nim (then Nimrod). According to Binstock, while Rust was "widely viewed as a remarkably elegant language", adoption slowed because it repeatedly changed between versions.[37]

Rust has a foreign function interface (FFI) that can be called from e.g. C language, and can call C. While calling C++ has historically been problematic (from any language), Rust has a library, CXX, to allow calling to or from C++, and "CXX has zero or negligible overhead".[38]

In August 2020, Mozilla laid off 250 of its 1,000 employees worldwide as part of a corporate restructuring caused by the long-term impact of the COVID-19 pandemic.[39][40] Among those laid off were most of the Rust team,[41] while the Servo team was completely disbanded.[42] The event raised concerns about the future of Rust.[43]

In the following week, the Rust Core Team acknowledged the severe impact of the layoffs and announced that plans for a Rust foundation were underway. The first goal of the foundation would be taking ownership of all trademarks and domain names, and also take financial responsibility for their costs.[44]

On February 8, 2021 the formation of the Rust Foundation was officially announced by its five founding companies (AWS, Huawei, Google, Microsoft, and Mozilla).[45][46]

On April 6, 2021, Google announced support for Rust within Android Open Source Project as an alternative to C/C++.[47]


Here is a "Hello, World!" program written in Rust. The println! macro prints the message to standard output.

fn main() {
    println!("Hello, World!");

The syntax of Rust is similar to C and C++, with blocks of code delimited by curly brackets, and control flow keywords such as if, else, while, and for, although the specific syntax for defining functions is more similar to Pascal. Despite the resemblance to C and C++, the syntax of Rust in is closer to that of the ML family of languages and the Haskell language. Nearly every part of a function body is an expression,[48] even control flow operators. For example, the ordinary if expression also takes the place of C's ternary conditional, an idiom used by ALGOL 60. As in Lisp, a function need not end with a return expression: in this case if the semicolon is omitted, the last expression in the function creates the return value, as seen in the following recursive implementation of the factorial function:

fn factorial(i: u64) -> u64 {
    match i {
        0 => 1,
        n => n * factorial(n-1)

The following iterative implementation uses the ..= operator to create an inclusive range:

fn factorial(i: u64) -> u64 {


File:Rust 101.webm

Rust is intended to be a language for highly concurrent and highly safe systems,[49] and programming in the large, that is, creating and maintaining boundaries that preserve large-system integrity.[50] This has led to a feature set with an emphasis on safety, control of memory layout, and concurrency.

Memory safety

Rust is designed to be memory safe. It does not permit null pointers, dangling pointers, or data races.[51][52][53] Data values can be initialized only through a fixed set of forms, all of which require their inputs to be already initialized.[54] To replicate pointers being either valid or NULL, such as in linked list or binary tree data structures, the Rust core library provides an option type, which can be used to test whether a pointer has Some value or None.[52] Rust has added syntax to manage lifetimes, which are checked at compile time by the borrow checker. Unsafe code can subvert some of these restrictions using the unsafe keyword.[14]

Memory management

Rust does not use automated garbage collection. Memory and other resources are managed through the resource acquisition is initialization convention,[55] with optional reference counting. Rust provides deterministic management of resources, with very low overhead.(citation?) Rust favors stack allocation of values and does not perform implicit boxing.

There is the concept of references (using the & symbol), which does not involve run-time reference counting. The safety of such pointers is verified at compile time, preventing dangling pointers and other forms of undefined behavior. Rust's type system separates shared, immutable pointers of the form &T from unique, mutable pointers of the form &mut T. A mutable pointer can be coerced to an immutable pointer, but not vice versa.


Rust has an ownership system where all values have a unique owner, and the scope of the value is the same as the scope of the owner.[56][57] Values can be passed by immutable reference, using &T, by mutable reference, using &mut T, or by value, using T. At all times, there can either be multiple immutable references or one mutable reference (an implicit readers–writer lock). The Rust compiler enforces these rules at compile time and also checks that all references are valid.

Types and polymorphism

The type system supports a mechanism similar to type classes, called traits, inspired by the Haskell language. This is a facility for ad hoc polymorphism, achieved by adding constraints to type variable declarations.

Rust uses type inference for variables declared with the keyword let. Such variables do not require a value to be initially assigned to determine their type. A compile time error results if any branch of code leaves the variable without an assignment.[58] Variables assigned multiple times must be marked with the keyword mut.

Functions can be given generic parameters, which usually require the generic type to implement a certain trait or traits. Within such a function, the generic value can only be used through those traits. This means that a generic function can be type-checked as soon as it is defined.

The implementation of Rust generics is similar to the typical implementation of C++ templates: a separate copy of the code is generated for each instantiation. This is called monomorphization and contrasts with the type erasure scheme typically used in Java and Haskell. Type erasure is also available in Rust by using the keyword dyn. The benefit of monomorphization is optimized code for each specific use case; the drawback is increased compile time and size of the resulting binaries.

The object system within Rust is based around implementations, traits and structured types. Implementations fulfill a role similar to that of classes within other languages and are defined with the keyword impl. Inheritance and polymorphism are provided by traits; they allow methods to be defined and mixed in to implementations. Structured types are used to define fields. Implementations and traits cannot define fields themselves, and only traits can provide inheritance. Among other benefits, this prevents the diamond problem of multiple inheritance, as in C++. In other words, Rust supports interface inheritance, but replaces implementation inheritance with composition; see composition over inheritance.


Rust features a large number of components that extend the Rust feature set and make Rust development easier. Component installation is typically managed by rustup, a Rust toolchain installer developed by the Rust project.[59]


Cargo is Rust's build system and package manager. Cargo handles downloading dependencies, and building dependencies. Cargo also acts as a wrapper for clippy and other Rust components. It requires projects to follow a certain directory structure.[60]

The dependencies for a Rust package are specified in a Cargo.toml file along with version requirements, telling Cargo which versions of the dependency are compatible with the package. By default, Cargo sources its dependencies from the user-contributed registry but Git repositories and packages in the local filesystem can be specified as dependencies, too.[61]


Rustfmt is a code formatter for Rust. It takes Rust source code as input and changes the whitespace and indentation to produce formatted code in accordance to the Rust style guide.[62] Rustfmt can also check whether the input is correctly formatted.[63]


Clippy is Rust's built in linting tool to improve the correctness, performance, and readability of Rust code. As of 2021, Clippy has more than 450 rules,[64] which can be browsed online and filtered by category.[65] Some rules are disabled by default.


RLS is a language server that provides IDEs and text editors with more information about a Rust project. It provides linting checks via Clippy, formatting via Rustfmt, automatic code completion via Racer, among other functions.[66] Development of Racer was slowed down in favor of rust-analyzer.[67]

Language extensions

It is possible to extend the Rust language using the procedural macro mechanism.[68]

Procedural macros use Rust functions that run at compile time to modify the token stream that is processed by the compiler. This complements the user defined macro mechanism which uses pattern matching to achieve similar goals.

Procedural macros come in three flavors:

  • Function-like macros custom!(...)
  • Derive macros #[derive(CustomDerive)]
  • Attribute macros #[CustomAttribute]

The println! macro is an example of a function-like macro and serde_derive[69] is a commonly used library for generating code for reading and writing data in many formats such as JSON. Attribute macros are commonly used for language bindings such as the extendr library for Rust bindings to R.[70]

The following code shows the use of the Serialize, Deserialize and Debug derive procedural macros to implement JSON reading and writing as well as the ability to format a structure for debugging.

use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug)]
struct Point {
    x: i32,
    y: i32,

fn main() {
    let point = Point { x: 1, y: 2 };

    let serialized = serde_json::to_string(&point).unwrap();
    println!("serialized = {}", serialized);

    let deserialized: Point = serde_json::from_str(&serialized).unwrap();
    println!("deserialized = {:?}", deserialized);


Rust aims "to be as efficient and portable as idiomatic C++, without sacrificing safety".[71] Since Rust utilizes LLVM, any performance improvements in LLVM also carry over to Rust.[72]


A bright orange crab icon
Some Rust users refer to themselves as Rustaceans (a pun on crustacean) and use Ferris as their unofficial mascot.[73]

Rust was the third-most-loved programming language in the 2015 Stack Overflow annual survey[74] and took first place for 2016–2021.[75][76]

Web browsers

Firefox has two projects written in Rust: the Servo parallel browser engine[77] developed by Mozilla in collaboration with Samsung;[78] and Quantum, which is composed of several sub-projects for improving Mozilla's Gecko browser engine.[79]

Experimental operating systems

  • Redox, a "full-blown Unix-like operating system" including a microkernel[80]
  • Theseus, OS with "intralingual design" and a fundamental architecture which embodies Rust concepts[81]



Rust Foundation
Rust Foundation logo.png
FormationFebruary 8, 2021; 7 months ago (2021-02-08)
TypeNonprofit organization
Shane Miller
Executive Director
Ashley Williams (interim)

The Rust Foundation is a non-profit membership organization incorporated in Delaware, United States , with the primary purposes of supporting the maintenance and development of the language, cultivating the Rust project team members and user communities, managing the technical infrastructure underlying the development of Rust, and managing and stewarding the Rust trademark.

It was established on February 8, 2021, with five founding corporate members (Amazon Web Services, Huawei, Google, Microsoft, and Mozilla).[96]

The foundation's board is chaired by Shane Miller.[97] Its interim Executive Director is Ashley Williams.


Rust conferences include:

  • RustConf: an annual conference in Portland, Oregon . Held annually since 2016 (except in 2020 and 2021 because of the COVID-19 pandemic).[98]
  • Rust Belt Rust: a #rustlang conference in the Rust Belt[99]
  • RustFest: Europe's @rustlang conference[100]
  • RustCon Asia
  • Rust LATAM
  • Oxidize Global[101]

See also


  1. 2.00 2.01 2.02 2.03 2.04 2.05 2.06 2.07 2.08 2.09 2.10 2.11 2.12 "The Rust Reference: Appendix: Influences". 
  2. "Note Research: Type System". 2015-02-01. 
  3. "RFC for 'if let' expression". 
  4. "Command Optimizations?". 2014-06-26.!searchin/elm-discuss/rust/elm-discuss/lMX_9miTD2E/QBwdvL4JD9wJ. 
  5. "Idris – Uniqueness Types". 
  6. Jaloyan, Georges-Axel (19 October 2017). Safe Pointers in SPARK 2014. Bibcode2017arXiv171007047J. 
  7. Lattner, Chris. "Chris Lattner's Homepage". 
  8. "Microsoft opens up Rust-inspired Project Verona programming language on GitHub". 
  9. "PHP RFC: Shorter Attribute Syntax". 2020-06-03. 
  10. Hoare, Graydon (2016-12-28). "Rust is mostly safety". Dreamwidth Studios. 
  11. 12.0 12.1 12.2 "FAQ – The Rust Project". 
  12. "Rust vs. C++ Comparison". 
  13. 14.0 14.1 "Unsafe Rust". 
  14. "Fearless Security: Memory Safety". 
  15. "Rc<T>, the Reference Counted Smart Pointer". 
  16. Noel (2010-07-08). "The Rust Language". Lambda the Ultimate. 
  17. "Contributors to rust-lang/rust". 
  18. Bright, Peter (2013-04-03). "Samsung teams up with Mozilla to build browser engine for multicore machines". 
  19. "Why Rust for safe systems programming". 
  20. "How Microsoft Is Adopting Rust". August 6, 2020. 
  21. "Stack Overflow Developer Survey 2021". 
  22. Hoare, Graydon (2014-06-07). "Internet archaeology: the definitive, end-all source for why Rust is named "Rust"". 
  23. "Future Tense". 2011-04-29. 
  24. Hoare, Graydon (7 July 2010). "Project Servo". Mozilla Annual Summit 2010. Whistler, Canada. Retrieved 22 February 2017. 
  25. Hoare, Graydon (2010-10-02). "Rust Progress". 
  26. Hoare, Graydon (2011-04-20). "[rust-dev] stage1/rustc builds". 
  27. catamorphism (2012-01-20). "Mozilla and the Rust community release Rust 0.1 (a strongly-typed systems programming language with a focus on memory safety and concurrency)". 
  28. "Version History". 
  29. The Rust Core Team (May 15, 2015). "Announcing Rust 1.0". 
  30. "Scheduling the Trains". 
  31. "G - How Rust is Made and "Nightly Rust" - The Rust Programming Language". 
  32. "What are editions? - The Edition Guide". 
  33. Strom, Robert E.; Yemini, Shaula (1986). "Typestate: A Programming Language Concept for Enhancing Software Reliability". IEEE Transactions on Software Engineering: 157–171. doi:10.1109/TSE.1986.6312929. ISSN 0098-5589. Retrieved 2010-11-14. 
  34. Walton, Patrick (2012-12-26). "Typestate Is Dead, Long Live Typestate!". 
  35. Biffle, Cliff (2019-06-05). "The Typestate Pattern in Rust". 
  36. Binstock, Andrew. "The Rise And Fall of Languages in 2013". 
  37. "Safe Interoperability between Rust and C++ with CXX" (in en). 2020-12-06. 
  38. Cimpanu, Catalin (2020-08-11). "Mozilla lays off 250 employees while it refocuses on commercial products". 
  39. Cooper, Daniel (2020-08-11). "Mozilla lays off 250 employees due to the pandemic". 
  40. @tschneidereit (2020-08-12). "Much of the team I used to manage was part of the Mozilla layoffs on Tuesday. That team was Mozilla's Rust team, and Mozilla's Wasmtime team. I thought I'd know how to talk about it by now, but I don't. It's heartbreaking, incomprehensible, and staggering in its impact.". 
  41. @asajeffrey (2020-08-11). "Mozilla is closing down the team I'm on, so I am one of the many folks now wondering what the next gig will be. It's been a wild ride!". 
  42. Kolakowski, Nick (2020-08-27). "Is Rust in Trouble After Big Mozilla Layoffs?". 
  43. "Laying the foundation for Rust's future". 2020-08-18. 
  44. "Rust Foundation" (in en). 2021-02-08. 
  45. "Mozilla Welcomes the Rust Foundation" (in en-US). 2021-02-09. 
  46. Amadeo, Ron (2021-04-07). "Google is now writing low-level Android code in Rust" (in en-us). 
  47. "rust/src/grammar/parser-lalr.y". 2017-05-23. 
  48. Avram, Abel (2012-08-03). "Interview on Rust, a Systems Programming Language Developed by Mozilla". InfoQ. 
  49. "Debian -- Details of package rustc in sid". 
  50. Rosenblatt, Seth (2013-04-03). "Samsung joins Mozilla's quest for Rust". 
  51. 52.0 52.1 Brown, Neil (2013-04-17). "A taste of Rust". 
  52. "Races - The Rustonomicon". 
  53. "The Rust Language FAQ". 2015. 
  54. "RAII – Rust By Example". 
  55. Klabnik, Steve; Nichols, Carol (June 2018). "Chapter 4: Understanding Ownership" (in en). The Rust Programming Language. San Francisco, California: No Starch Press. p. 44. ISBN 978-1-593-27828-1. Retrieved 2019-05-14. 
  56. "The Rust Programming Language: What is Ownership" (in en). 
  57. Walton, Patrick (2010-10-01). "Rust Features I: Type Inference". 
  58. rust-lang/rustup, The Rust Programming Language, 2021-05-17,, retrieved 2021-05-17 
  59. "Why Cargo Exists". 
  60. "Specifying Dependencies - The Cargo Book". 
  61. "rust-dev-tools/fmt-rfcs" (in en). 
  62. "rustfmt". 
  63. "rust-lang/rust-clippy" (in en). 
  64. "ALL the Clippy Lints". 
  65. "rust-lang/rls" (in en). 
  66. "racer-rust/racer" (in en). 
  67. "Procedural Macros". 
  68. "Serde Derive". 
  69. "extendr_api - Rust". 
  70. Walton, Patrick (2010-12-05). "C++ Design Goals in the Context of Rust". 
  71. "How Fast Is Rust?". 
  72. "Getting Started". 
  73. "Stack Overflow Developer Survey 2015". 
  74. "Stack Overflow Developer Survey 2019". 
  75. "Stack Overflow Developer Survey 2021". 
  76. Yegulalp, Serdar (2015-04-03). "Mozilla's Rust-based Servo browser engine inches forward". InfoWorld. 
  77. Lardinois, Frederic (2015-04-03). "Mozilla And Samsung Team Up To Develop Servo, Mozilla's Next-Gen Browser Engine For Multicore Processors". TechCrunch. 
  78. Bryant, David (27 October 2016). "A Quantum Leap for the web". 
  79. Yegulalp, Serdar. "Rust's Redox OS could show Linux a few new tricks". infoworld. 
  80. "Introduction to Theseus" (in en). 
  81. Garbutt, James (27 January 2019). "First thoughts on Deno, the JavaScript/TypeScript run-time". 
  82. Howarth, Jesse (2020-02-04). "Why Discord is switching from Go to Rust". 
  83. Vishnevskiy, Stanislav (July 6, 2017). "How Discord Scaled Elixir to 5,000,000 Concurrent Users". 
  84. "Google Fushcia's source code" (in en). 
  85. Nichols, Shaun (27 June 2018). "Microsoft's next trick? Kicking things out of the cloud to Azure IoT Edge" (in en). 
  86. Balbaert, Ivo (27 May 2015). Rust Essentials. Packt Publishing. p. 6. ISBN 978-1785285769. Retrieved 21 March 2016. 
  87. Frank, Denis (5 December 2013). "Using HyperLogLog to Detect Malware Faster Than Ever". 
  88. Denis, Frank (4 October 2013). "ZeroMQ: Helping us Block Malicious Domains in Real Time". 
  89. "Ruffle" (in en). 
  90. Sei, Mark (10 October 2018). "Fedora 29 new features: Startis now officially in Fedora". 
  91. "RHEL 8: Chapter 8. Managing layered local storage with Stratis". 10 October 2018. 
  92. Hahn, Sebastian (2017-03-31). "[tor-dev Tor in a safer language: Network team update from Amsterdam"]. 
  93. asn (2017-07-05). "The Wilmington Watch: A Tor Network Team Hackfest". 
  94. terminusdb/terminusdb-store, TerminusDB, 2020-12-14,, retrieved 2020-12-14 
  95. Krill, Paul. "Rust language moves to independent foundation". InfoWorld. 
  96. Vaughan-Nichols, Steven J. (9 April 2021). "AWS's Shane Miller to head the newly created Rust Foundation". ZDNet. 
  97. "RustConf 2020 - Thursday, August 20". 
  98. "Rust Belt Rust". Dayton, Ohio. 2019-10-18. Retrieved 2019-05-14. 
  99. "RustFest". Barcelona, Spain: asquera Event UG. 2019. Retrieved 2019-05-14. 
  100. "Oxidize Global". 

Cite error: <ref> tag with name "mozilla-research" defined in <references> is not used in prior text.
Cite error: <ref> tag with name "RustPlatforms" defined in <references> is not used in prior text.
Cite error: <ref> tag with name "EmbeddedFAQ" defined in <references> is not used in prior text.
Cite error: <ref> tag with name "OpenBSD" defined in <references> is not used in prior text.

Cite error: <ref> tag with name "rust-on-ios" defined in <references> is not used in prior text.

External links