Rust (programming language)#Hello World program

{{Short description|General-purpose programming language}}

{{Good article}}

{{Use American English|date=July 2022}}

{{Use mdy dates|date=July 2022|cs1-dates=y}}

{{Infobox programming language

| name = Rust

| logo = Rust programming language black logo.svg

| logo size = 150px

| logo alt = Rust logo; a capital letter R set into a sprocket

| paradigms = {{cslist|

Concurrent|

functional|

generic|

imperative|

structured|

}}

| released = {{Start date and age|2012|01|19}}

| developer = The Rust Team

| latest release version = {{wikidata|property|edit|reference|P548=Q2804309|P348}}

| latest release date = {{start date and age|{{wikidata|qualifier|mdy|P548=Q2804309|P348|P577}}}}

| typing = {{cslist|

Affine|

inferred|

nominal|

static|

strong|

}}

| programming language = OCaml (2006–2011)
Rust (2012–present)

| platform = Cross-platform{{refn|group=note|Including build tools, host tools, and standard library support for x86-64, ARM, MIPS, RISC-V, WebAssembly, i686, AArch64, PowerPC, and s390x.{{Cite web |title=Platform Support |website=The rustc book |url=https://doc.rust-lang.org/rustc/platform-support.html |access-date=2022-06-27 |archive-date=2022-06-30 |archive-url=https://web.archive.org/web/20220630164523/https://doc.rust-lang.org/rustc/platform-support.html |url-status=live }}}}

| operating system = Cross-platform{{refn|group=note|Including Windows, Linux, macOS, FreeBSD, NetBSD, and Illumos. Host build tools on Android, iOS, Haiku, Redox, and Fuchsia are not officially shipped; these operating systems are supported as targets.}}

| license = MIT, Apache 2.0{{refn|group=note|Third-party dependencies, e.g., LLVM or MSVC, are subject to their own licenses.{{cite web |title=Copyright |url=https://github.com/rust-lang/rust/blob/master/COPYRIGHT |website=GitHub |publisher=The Rust Programming Language |date=19 October 2022 |access-date=2022-10-19 |archive-date=2023-07-22 |archive-url=https://web.archive.org/web/20230722190056/http://github.com/rust-lang/rust/blob/master/COPYRIGHT |url-status=live }}}}

| file ext = .rs, .rlib

| website = {{url|https://www.rust-lang.org/|rust-lang.org}}

| influenced by = {{cslist|

Alef|

BETA|

CLU|

C#|

C++|

Cyclone|

Elm|

Erlang|

Haskell|

Hermes|

Limbo|

Mesa|

Napier|

Newsqueak|

NIL|

OCaml|

Ruby|

Sather|

Scheme|

Standard ML|

Swift{{Cite web |title=Uniqueness Types |url=https://blog.rust-lang.org/2016/08/10/Shape-of-errors-to-come.html |access-date=2016-10-08 |website=Rust Blog |quote="Those of you familiar with the Elm style may recognize that the updated {{mono|--explain}} messages draw heavy inspiration from the Elm approach." |archive-date=2016-09-15 |archive-url=https://web.archive.org/web/20160915133745/https://blog.rust-lang.org/2016/08/10/Shape-of-errors-to-come.html |url-status=live }}

}}

| influenced = {{cslist|

Idris{{Cite web |title=Uniqueness Types |url=http://docs.idris-lang.org/en/latest/reference/uniqueness-types.html |access-date=2022-07-14 |website=Idris 1.3.3 documentation |quote="They are inspired by ... ownership types and borrowed pointers in the Rust programming language." |archive-date=2018-11-21 |archive-url=https://web.archive.org/web/20181121072557/http://docs.idris-lang.org/en/latest/reference/uniqueness-types.html |url-status=live }}|

Project Verona|

SPARK|

Swift|

V{{Cite web |title=V documentation (Introduction) |url=https://github.com/vlang/v/blob/master/doc/docs.md#introduction |access-date=2023-11-04 |website=GitHub |publisher=The V Programming Language |language=en}}|

Zig{{Cite web |last=Yegulalp |first=Serdar |date=2016-08-29 |title=New challenger joins Rust to topple C language |url=https://www.infoworld.com/article/3113083/new-challenger-joins-rust-to-upend-c-language.html |access-date=2022-10-19 |website=InfoWorld |language=en |archive-date=2021-11-25 |archive-url=https://web.archive.org/web/20211125104022/https://www.infoworld.com/article/3113083/new-challenger-joins-rust-to-upend-c-language.html |url-status=live }}|

}}

}}

Rust is a general-purpose programming language emphasizing performance, type safety, and concurrency. It enforces memory safety, meaning that all references point to valid memory. It does so 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.

Rust does not enforce a programming paradigm, but 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. It is popular for systems programming.{{Cite book |last1=Eshwarla |first1=Prabhu |date=2020-12-24 |url=https://books.google.com/books?id=eEUREAAAQBAJ |title=Practical System Programming for Rust Developers: Build fast and secure software for Linux/Unix systems with the help of practical examples |publisher=Packt Publishing Ltd |isbn=978-1-80056-201-1 |language=en}}{{Cite journal |last1=Blanco-Cuaresma |first1=Sergi |last2=Bolmont |first2=Emeline |date=2017-05-30 |title=What can the programming language Rust do for astrophysics? |url=https://www.cambridge.org/core/journals/proceedings-of-the-international-astronomical-union/article/what-can-the-programming-language-rust-do-for-astrophysics/B51B6DF72B7641F2352C05A502F3D881 |journal=Proceedings of the International Astronomical Union |language=en |volume=12 |issue=S325 |pages=341–344 |doi=10.1017/S1743921316013168 |arxiv=1702.02951 |bibcode=2017IAUS..325..341B |s2cid=7857871 |issn=1743-9213 |archive-date=2022-06-25 |access-date=2022-06-25 |archive-url=https://web.archive.org/web/20220625140128/https://www.cambridge.org/core/journals/proceedings-of-the-international-astronomical-union/article/what-can-the-programming-language-rust-do-for-astrophysics/B51B6DF72B7641F2352C05A502F3D881 |url-status=live }}{{sfn|Blandy|Orendorff|Tindall|2021}}

Software developer Graydon Hoare created Rust as a personal project while working at Mozilla Research in 2006. Mozilla officially sponsored the project in 2009. In the years following the first stable release in May 2015, Rust was adopted by companies including Amazon, Discord, Dropbox, Google (Alphabet), Meta, and Microsoft. In December 2022, it became the first language other than C and assembly to be supported in the development of the Linux kernel.

Rust has been noted for its rapid adoption, and has been studied in programming language theory research.

History

= Early years (2006–2009) =

File:MozillaCaliforniaHeadquarters.JPG]]

Rust began as a personal project by Mozilla employee Graydon Hoare in 2006.{{cite web |url=https://www.technologyreview.com/2023/02/14/1067869/rust-worlds-fastest-growing-programming-language/ |title=How Rust went from a side project to the world's most-loved programming language |last=Thompson |first=Clive |date=2023-02-14 |website=MIT Technology Review |language=en |access-date=2023-02-23 |archive-date=2024-09-19 |archive-url=https://web.archive.org/web/20240919102849/https://www.technologyreview.com/2023/02/14/1067869/rust-worlds-fastest-growing-programming-language/ |url-status=live }} Hoare has stated that Rust was named for the group of fungi that are "over-engineered for survival". During the time period between 2006 and 2009, Rust was not publicized to others at Mozilla and was written in Hoare's free time;{{Cite book |last=Klabnik |first=Steve |chapter=The History of Rust |date=2016-06-02 |title=Applicative 2016 |chapter-url=https://dl.acm.org/doi/10.1145/2959689.2960081 |page=80 |location=New York, NY, USA |publisher=Association for Computing Machinery |doi=10.1145/2959689.2960081 |isbn=978-1-4503-4464-7}}{{rp|at=7:50}} Hoare began speaking about the language around 2009 after a small group at Mozilla became interested in the project.{{Cite conference |url=http://venge.net/graydon/talks/intro-talk-2.pdf |archive-url=https://archive.today/20211226213836/http://venge.net/graydon/talks/intro-talk-2.pdf |archive-date=2021-12-26 |last=Hoare |first=Graydon |title=Project Servo: Technology from the past come to save the future from itself |publisher=Mozilla Annual Summit |date=July 2010 |access-date=2024-10-29 }} Hoare emphasized prioritizing good ideas from old languages over new development, citing languages including CLU (1974), BETA (1975), Mesa (1977), NIL (1981), Erlang (1987), Newsqueak (1988), Napier (1988), Hermes (1990), Sather (1990), Alef (1992), and Limbo (1996) as influences, stating "many older languages [are] better than new ones", and describing the language as "technology from the past come to save the future from itself."{{rp|at=8:17}} Early Rust developer Manish Goregaokar similarly described Rust as being based on "mostly decades-old research."

During the early years, the Rust compiler was written in about 38,000 lines of OCaml.{{rp|at=15:34}}{{Cite web |last=Hoare |first=Graydon |title=Rust Prehistory (Archive of the original Rust OCaml compiler source code) |website=GitHub |date=November 2016 |url=https://github.com/graydon/rust-prehistory/tree/master |access-date=2024-10-29 }} Early Rust contained features such as explicit object-oriented programming via an {{code|obj}} keyword (later removed),{{rp|at=10:08}} and a typestates system that would allow variables of a type to be tracked along with state changes (such as going from uninitialized to initialized).{{rp|at=13:12}}

= Mozilla sponsorship (2009–2012) =

Mozilla officially sponsored the Rust project in 2009. 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.

During this time period, work had shifted from the initial OCaml compiler to a self-hosting compiler, i.e., written in Rust, based on LLVM.{{Cite web |title=0.1 first supported public release Milestone · rust-lang/rust |url=https://github.com/rust-lang/rust/milestone/3?closed=1 |access-date=2024-10-29 |website=GitHub |language=en}}{{refn|group=note|The list of Rust compiler versions (referred to as a bootstrapping chain) has history going back to 2012.{{Cite AV media |url=https://www.youtube.com/watch?v=oUIjG-y4zaA |last=Nelson |first=Jynn |title=RustConf 2022 - Bootstrapping: The once and future compiler |publisher=Rust Team |date=2022-08-05 |access-date=2024-10-29 |location=Portland, Oregon |via=YouTube}}}} The Rust ownership system was also in place by 2010. The Rust logo was developed in 2011 based on a bicycle chainring.{{cite web |title=Rust logo |url=https://bugzilla.mozilla.org/show_bug.cgi?id=680521 |website=Bugzilla |access-date=2 February 2024 |archive-date=2024-02-02 |archive-url=https://web.archive.org/web/20240202045212/https://bugzilla.mozilla.org/show_bug.cgi?id=680521 |url-status=live }}

The first public release, Rust 0.1 was released on January 20, 2012{{Cite mailing list |last=Anderson |first=Brian |date=2012-01-24 |title=[rust-dev] The Rust compiler 0.1 is unleashed |url=https://mail.mozilla.org/pipermail/rust-dev/2012-January/001256.html |mailing-list=rust-dev |access-date=2025-01-07 |archive-url=https://web.archive.org/web/20120124160628/https://mail.mozilla.org/pipermail/rust-dev/2012-January/001256.html |archive-date=January 24, 2012 }} for Windows, Linux, and MacOS.{{Cite web |last=Anthony |first=Sebastian |date=2012-01-24 |title=Mozilla releases Rust 0.1, the language that will eventually usurp Firefox's C++ |url=https://www.extremetech.com/internet/115207-mozilla-releases-rust-0-1-the-language-that-will-eventually-usurp-firefoxs-c |access-date=2025-01-07 |website=ExtremeTech |language=en}} The early 2010s saw increasing involvement from open source volunteers outside of Mozilla and outside of the United States. At Mozilla, executives would eventually employ over a dozen engineers to work on Rust full time over the next decade.

= Evolution (2012–2015) =

The years from 2012 to 2015 were marked by substantial changes to the Rust type system, especially, removal of the typestate system, consolidation of other language features, and the removal of the garbage collector.{{rp|at=18:36}} Memory management through the ownership system was gradually consolidated and expanded to prevent memory-related bugs. By 2013, the garbage collector feature was rarely used, and was removed by the team in favor of the ownership system. Other changes during this time included the removal of pure functions, which were declared by an explicit {{code|pure}} annotation, in March 2013.{{Cite web |title=Purity by pcwalton · Pull Request #5412 · rust-lang/rust |url=https://github.com/rust-lang/rust/pull/5412 |access-date=2024-10-29 |website=GitHub |language=en}} Specialized syntax support for channels and various pointer types were removed to simplify the language.{{rp|at=22:32}}

Rust's expansion and consolidation was influenced 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., type systems development).{{rp|at=30:50}}

Graydon Hoare stepped down from Rust in 2013. This allowed it to evolve organically under a more federated governance structure, with a "core team" of initially six people,{{rp|at=21:45}} around 30-40 developers total across various other teams,{{rp|at=22:22}} and a Request for Comments (RFC) process for new language features added in March 2014.{{rp|at=33:47}} The core team would grow to nine people by 2016{{rp|at=21:45}} with over 1600 proposed RFCs.{{rp|at=34:08}}

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.{{cite news |last=Binstock |first=Andrew |date=January 7, 2014 |title=The Rise And Fall of Languages in 2013 |website=Dr. Dobb's Journal |url=https://www.drdobbs.com/jvm/the-rise-and-fall-of-languages-in-2013/240165192 |url-status=dead |archive-url=https://web.archive.org/web/20160807075745/http://www.drdobbs.com/jvm/the-rise-and-fall-of-languages-in-2013/240165192 |archive-date=2016-08-07 |access-date=2022-11-20}} Rust development at this time was focused on finalizing the language features and moving towards 1.0 so it could begin promising backward compatibility.{{rp|at=41:26}}

Six years after Mozilla sponsored its development, the first stable release, Rust 1.0, was published on May 15, 2015. A year after the release, the Rust compiler had accumulated over 1,400 contributors and there were over 5,000 third-party libraries published on the Rust package management website Crates.io.{{rp|at=43:15}}

= Servo and early adoption (2015–2020) =

File:Home page servo v0.01.png]]

The development of the Servo browser engine continued in parallel with Rust, jointly funded by Mozilla and Samsung.{{cite news|last=Lardinois|first=Frederic|date=2015-04-03|title=Mozilla And Samsung Team Up To Develop Servo, Mozilla's Next-Gen Browser Engine For Multicore Processors|work=TechCrunch|url=https://techcrunch.com/2013/04/03/mozilla-and-samsung-collaborate-on-servo-mozillas-next-gen-browser-engine-for-tomorrows-multicore-processors/|access-date=2017-06-25|archive-date=2016-09-10|archive-url=https://web.archive.org/web/20160910211537/https://techcrunch.com/2013/04/03/mozilla-and-samsung-collaborate-on-servo-mozillas-next-gen-browser-engine-for-tomorrows-multicore-processors/|url-status=live}} The teams behind the two projects worked in close collaboration; 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.{{rp|at=5:41}} The first version of Servo was released in 2016. The Firefox web browser shipped with Rust code as of 2016 (version 45),{{rp|at=53:30}}{{Cite web |title=Firefox 45.0, See All New Features, Updates and Fixes |url=https://www.mozilla.org/en-US/firefox/45.0/releasenotes/ |access-date=2024-10-31 |website=Mozilla |language=en |archive-date=2016-03-17 |archive-url=https://web.archive.org/web/20160317215950/https://www.mozilla.org/en-US/firefox/45.0/releasenotes/ |url-status=live }} but components of Servo did not appear in Firefox until September 2017 (version 57) as part of the Gecko and Quantum projects.{{Cite web |last=Lardinois |first=Frederic |date=2017-09-29 |title=It's time to give Firefox another chance |url=https://techcrunch.com/2017/09/29/its-time-to-give-firefox-another-chance/ |access-date=2023-08-15 |website=TechCrunch |language=en-US |archive-date=2023-08-15 |archive-url=https://web.archive.org/web/20230815025149/https://techcrunch.com/2017/09/29/its-time-to-give-firefox-another-chance/ |url-status=live }}

Improvements were made to the Rust toolchain ecosystem during the years following 1.0 including Rustfmt, integrated development environment integration,{{rp|at=44:56}} a regular compiler testing and release cycle,{{rp|at=46:48}} a community code of conduct, and community discussion organized through an IRC chat.{{rp|at=50:36}}

The earliest adoption outside of Mozilla was by individual projects at Samsung, Facebook (now Meta Platforms), Dropbox, and others including Tilde, Inc. (the company behind ember.js).{{rp|at=55:44}} Amazon Web Services followed in 2020. Engineers cited performance, lack of a garbage collector, safety, and pleasantness of working in the language as reasons for the adoption, while acknowledging that it was a risky bet as Rust was new technology. Amazon developers cited the fact that Rust uses half as much electricity as similar code written in Java, behind only C, as found by a study at the University of Minho, NOVA University Lisbon, and the University of Coimbra.{{Cite book |last1=Pereira |first1=Rui |last2=Couto |first2=Marco |last3=Ribeiro |first3=Francisco |last4=Rua |first4=Rui |last5=Cunha |first5=Jácome |last6=Fernandes |first6=João Paulo |last7=Saraiva |first7=João |chapter=Energy efficiency across programming languages: How do energy, time, and memory relate? |date=2017-10-23 |title=Proceedings of the 10th ACM SIGPLAN International Conference on Software Language Engineering |chapter-url=https://dl.acm.org/doi/10.1145/3136014.3136031 |series=SLE 2017 |location=New York, NY, USA |publisher=Association for Computing Machinery |pages=256–267 |doi=10.1145/3136014.3136031 |hdl=1822/65359 |isbn=978-1-4503-5525-4}}{{refn|group=note|Energy compared to C was 3% more for Rust and 34% more for C++; time was 4% more and 56% more, respectively.}}

= Mozilla layoffs and Rust Foundation (2020–present) =

In August 2020, Mozilla laid off 250 of its 1,000 employees worldwide, as part of a corporate restructuring caused by the COVID-19 pandemic.{{cite web |url=https://www.zdnet.com/article/mozilla-lays-off-250-employees-while-it-refocuses-on-commercial-products/ |title=Mozilla lays off 250 employees while it refocuses on commercial products |last=Cimpanu |first=Catalin |website=ZDNET |access-date=2020-12-02 |date=2020-08-11 |archive-date=March 18, 2022 |archive-url=https://web.archive.org/web/20220318025804/https://www.zdnet.com/article/mozilla-lays-off-250-employees-while-it-refocuses-on-commercial-products/ |url-status=live}}{{cite web |url=https://www.engadget.com/mozilla-firefox-250-employees-layoffs-151324924.html |title=Mozilla lays off 250 employees due to the pandemic |website=Engadget |last=Cooper |first=Daniel |access-date=2020-12-02 |date=2020-08-11 |archive-date=2020-12-13 |archive-url=https://web.archive.org/web/20201213020220/https://www.engadget.com/mozilla-firefox-250-employees-layoffs-151324924.html |url-status=live}} The team behind Servo was disbanded. The event raised concerns about the future of Rust, due to the overlap between the two projects.{{Cite web |last=Tung |first=Liam |date=2020-08-21 |title=Programming language Rust: Mozilla job cuts have hit us badly but here's how we'll survive |url=https://www.zdnet.com/article/programming-language-rust-mozilla-job-cuts-have-hit-us-badly-but-heres-how-well-survive/ |access-date=2022-04-21 |website=ZDNET |language=en |archive-date=April 21, 2022 |archive-url=https://web.archive.org/web/20220421083509/https://www.zdnet.com/article/programming-language-rust-mozilla-job-cuts-have-hit-us-badly-but-heres-how-well-survive/ |url-status=live}} 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 to take ownership of all trademarks and domain names, and take financial responsibility for their costs.{{cite web |url=https://blog.rust-lang.org/2020/08/18/laying-the-foundation-for-rusts-future.html |title=Laying the foundation for Rust's future |website=Rust Blog |access-date=2020-12-02 |date=2020-08-18 |archive-date=2020-12-02 |archive-url=https://web.archive.org/web/20201202022933/https://blog.rust-lang.org/2020/08/18/laying-the-foundation-for-rusts-future.html |url-status=live}}

On February 8, 2021, the formation of the Rust Foundation was announced by five founding companies: Amazon Web Services, Google, Huawei, Microsoft, and Mozilla.{{Cite web |date=2020-02-08 |title=Hello World! |url=https://foundation.rust-lang.org/news/2021-02-08-hello-world/ |access-date=2022-06-04 |website=Rust Foundation |language=en |archive-date=April 19, 2022 |archive-url=https://web.archive.org/web/20220419124635/https://foundation.rust-lang.org/news/2021-02-08-hello-world/ |url-status=live}}{{Cite web|date=2021-02-09|title=Mozilla Welcomes the Rust Foundation |website=Mozilla Blog |url=https://blog.mozilla.org/blog/2021/02/08/mozilla-welcomes-the-rust-foundation |archive-url=https://web.archive.org/web/20210208212031/https://blog.mozilla.org/blog/2021/02/08/mozilla-welcomes-the-rust-foundation/|archive-date=2021-02-08|access-date=2021-02-09|url-status=live}} The foundation, led by Shane Miller for its first two years, offered $20,000 grants and other support for programmers working on major Rust features. In a blog post published on April 6, 2021, Google announced support for Rust within the Android Open Source Project as an alternative to C/C++.{{Cite web|last=Amadeo|first=Ron|date=2021-04-07 |title=Google is now writing low-level Android code in Rust |url=https://arstechnica.com/gadgets/2021/04/google-is-now-writing-low-level-android-code-in-rust/ |access-date=2021-04-08|website=Ars Technica|language=en-us|archive-date=2021-04-08|archive-url=https://web.archive.org/web/20210408001446/https://arstechnica.com/gadgets/2021/04/google-is-now-writing-low-level-android-code-in-rust/|url-status=live}}

On November 22, 2021, the Moderation Team, which was responsible for enforcing the community code of conduct, announced their resignation "in protest of the Core Team placing themselves unaccountable to anyone but themselves".{{Cite news |first=Tim |last=Anderson |title=Entire Rust moderation team resigns |url=https://www.theregister.com/2021/11/23/rust_moderation_team_quits/ |date=2021-11-23 |access-date=2022-08-04 |website=The Register |language=en |archive-date=2022-07-14 |archive-url=https://web.archive.org/web/20220714093245/https://www.theregister.com/2021/11/23/rust_moderation_team_quits/ |url-status=live }} In May 2022, the Rust Core Team, other lead programmers, and certain members of the Rust Foundation board implemented governance reforms in response to the incident.{{Cite web |title=Governance Update |url=https://blog.rust-lang.org/inside-rust/2022/05/19/governance-update.html |access-date=2022-10-27 |website=Inside Rust Blog |language=en |archive-date=2022-10-27 |archive-url=https://web.archive.org/web/20221027030926/https://blog.rust-lang.org/inside-rust/2022/05/19/governance-update.html |url-status=live }}

The Rust Foundation posted a draft for a new trademark policy on April 6, 2023, including rules for how the Rust logo and name can be used, which resulted in negative reactions from Rust users and contributors.{{Cite news |last=Claburn |first=Thomas |title=Rust Foundation apologizes for trademark policy confusion |date=2023-04-17 |url=https://www.theregister.com/2023/04/17/rust_foundation_apologizes_trademark_policy/ |access-date=2023-05-07 |website=The Register |language=en |archive-date=2023-05-07 |archive-url=https://web.archive.org/web/20230507053637/https://www.theregister.com/2023/04/17/rust_foundation_apologizes_trademark_policy/ |url-status=live }}

On February 26, 2024, the U.S. White House released a 19-page press report urging software development to move to memory-safe programming languages; specifically, moving away from C and C++ and encouraging languages like C#, Go, Java, Ruby, Swift, and Rust.{{Cite web |last=Gross |first=Grant |title=White House urges developers to dump C and C++ |url=https://www.infoworld.com/article/2336216/white-house-urges-developers-to-dump-c-and-c.html |date=2024-02-27 |access-date=2025-01-26 |website=InfoWorld |language=en}}{{Cite web |last=Warminsky |first=Joe |date=2024-02-27 |title=After decades of memory-related software bugs, White House calls on industry to act |url=https://therecord.media/memory-related-software-bugs-white-house-code-report-oncd |access-date=2025-01-26 |website=The Record |language=en}} The report was widely interpreted as increasing interest in Rust.{{Cite web |last=Jack |first=Bobby |date=2024-02-29 |title=The White House Wants Memory-Safe Programming, but What Is That? |url=https://www.makeuseof.com/memory-safe-programming-white-house-wants/ |access-date=2025-01-26 |website=MakeUseOf |language=en}}{{Cite web |last=Donovan |first=Ryan |date=2024-12-30 |title=In Rust we trust? White House Office urges memory safety |url=https://stackoverflow.blog/2024/12/30/in-rust-we-trust-white-house-office-urges-memory-safety/ |access-date=2025-01-26 |website=The Stack Overflow Blog |language=en}} The report was released through the Office of the National Cyber Director.{{Cite web |date=2024-02-26 |title=Press Release: Future Software Should Be Memory Safe |url=https://www.whitehouse.gov/oncd/briefing-room/2024/02/26/press-release-technical-report/ |archive-url=https://web.archive.org/web/20250118013136/https://www.whitehouse.gov/oncd/briefing-room/2024/02/26/press-release-technical-report/ |publisher=The White House |url-status=dead |archive-date=2025-01-18 |access-date=2025-01-26 }}

Syntax and features

Rust's syntax is similar to that of C and C++,{{Cite news |last=Proven |first=Liam |date=2019-11-27 |title=Rebecca Rumbul named new CEO of The Rust Foundation |url=https://www.theregister.com/2021/11/19/rust_foundation_ceo/ |access-date=2022-07-14 |website=The Register |language=en |quote="Both are curly bracket languages, with C-like syntax that makes them unintimidating for C programmers." |archive-date=2022-07-14 |archive-url=https://web.archive.org/web/20220714110957/https://www.theregister.com/2021/11/19/rust_foundation_ceo/ |url-status=live }} although many of its features were influenced by functional programming languages such as OCaml.{{sfn|Klabnik|Nichols|2019|p=263}} Hoare has described Rust as targeted at frustrated C++ developers and emphasized features such as safety, control of memory layout, and concurrency. Safety in Rust includes the guarantees of memory safety, type safety, and lack of data races.

= Hello World program =

Below is a "Hello, World!" program in Rust. The {{Rust|fn}} keyword denotes a function, and the {{Rust|println!}} macro (see {{Section link|2=Macros|nopage=y}}) prints the message to standard output.{{sfn|Klabnik|Nichols|2019|pp=5–6}} Statements in Rust are separated by semicolons.

fn main() {

println!("Hello, World!");

}

= Variables =

Variables in Rust are defined through the {{rust|let}} keyword.{{sfn|Klabnik|Nichols|2023|p=32}} The example below assigns a value to the variable with name {{code|foo}} and outputs its value.

fn main() {

let foo = 10;

println!("The value of foo is {foo}");

}

Variables are immutable by default, but adding the {{rust|mut}} keyword allows the variable to be mutated.{{sfn|Klabnik|Nichols|2023|pp=32-33}} The following example uses {{code|//}}, which denotes the start of a comment.{{sfn|Klabnik|Nichols|2023|pp=49-50}}

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 {{code|let}} 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.{{sfn|Klabnik|Nichols|2023|pp=34-36}} 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:{{sfn|Klabnik|Nichols|2023|pp=6,47,53}}

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:{{sfn|Klabnik|Nichols|2023|pp=47-48}}

fn add_two(x: i32) -> i32 {

x + 2

}

== {{code|if}} expressions ==

An {{rust|if}} conditional expression executes code based on whether the given value is {{code|true}}. {{rust|else}} can be used for when the value evaluates to {{code|false}}, and {{rust|else if}} can be used for combining multiple expressions.{{sfn|Klabnik|Nichols|2023|pp=50-53}}

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");

}

}

{{rust|if}} and {{rust|else}} blocks can evaluate to a value, which can then be assigned to a variable:{{sfn|Klabnik|Nichols|2023|pp=50-53}}

fn main() {

let x = 10;

let new_x = if x % 2 == 0 { x / 2 } else { 3 * x + 1 };

println!("{new_x}");

}

== {{code|while}} loops ==

while can be used to repeat a block of code while a condition is met.{{sfn|Klabnik|Nichols|2023|p=56}}

fn main() {

// Iterate over all integers from 4 to 10

let mut value = 4;

while value <= 10 {

println!("value = {value}");

value += 1;

}

}

== {{code|for}} loops and iterators ==

For loops in Rust loop over elements of a collection.{{sfn|Klabnik|Nichols|2023|pp=57-58}}

{{rust|for}} 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, {{rust|1=4..=10}} is a value of type {{rust|Range}} which implements the {{rust|Iterator}} 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 {{rust|map}}, {{rust|filter}}, and {{rust|sum}}. 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()

== {{code|loop}} and {{code|break}} statements ==

More generally, the {{rust|loop}} keyword allows repeating a portion of code until a {{rust|break}} occurs. {{rust|break}} may optionally exit the loop with a value. In the case of nested loops, labels denoted by {{rust|'label_name}} can be used to break an outer loop rather than the innermost loop.{{sfn|Klabnik|Nichols|2023|pp=54-56}}

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 =

The {{rust|match}} and {{rust|if let}} expressions can be used for pattern matching. For example, {{rust|match}} can be used to double an optional integer value if present, and return zero otherwise:{{sfn|Klabnik|Nichols|2019|pp=104–109}}

fn double(x: Option) -> u64 {

match x {

Some(y) => y * 2,

None => 0,

}

}

Equivalently, this can be written with {{rust|if let}} and {{rust|else}}:

fn double(x: Option) -> u64 {

if let Some(y) = x {

y * 2

} else {

0

}

}

= Types =

Rust is strongly typed and statically typed, meaning that the types of all variables must be known at compilation time. Assigning a value of a particular type to a differently typed variable causes a compilation error. Type inference is used to determine the type of variables if unspecified.{{sfn|Klabnik|Nichols|2019|pp=24}}

The default integer type is {{rust|i32}}, and the default floating point type is {{rust|f64}}. If the type of a literal number is not explicitly provided, it is either inferred from the context or the default type is used.{{sfn|Klabnik|Nichols|2019|pp=36–38}}

== Primitive types ==

Integer types in Rust are named based on the signedness and the number of bits the type takes. For example, {{rust|i32}} is a signed integer that takes 32 bits of storage, whereas {{code|u8}} is unsigned and only takes 8 bits of storage. {{rust|isize}} and {{rust|usize}} take storage depending on the architecture of the computer that runs the code, for example, on computers with 32-bit architectures, both types will take up 32 bits of space.

By default, integer literals are in base-10, but different radices are supported with prefixes, for example, {{rust|0b11}} for binary numbers, {{rust|0o567}} for octals, and {{rust|0xDB}} for hexadecimals. By default, integer literals default to {{rust|i32}} as its type. Suffixes such as {{rust|4u32}} can be used to explicitly set the type of a literal.{{sfn|Klabnik|Nichols|2023|pp=36-38}} Byte literals such as {{rust|b'X'}} are available to represent the ASCII value (as a {{rust|u8}}) of a specific character.{{sfn|Klabnik|Nichols|2023|p=502}}

The Boolean type is referred to as {{rust|bool}} which can take a value of either {{rust|true}} or {{rust|false}}. A {{rust|char}} takes up 32 bits of space and represents a Unicode scalar value: a Unicode codepoint that is not a surrogate.{{Cite web |title=Glossary of Unicode Terms |url=https://www.unicode.org/glossary/ |access-date=2024-07-30 |website=Unicode Consortium |archive-date=2018-09-24 |archive-url=https://web.archive.org/web/20180924092749/http://www.unicode.org/glossary/ |url-status=live }} IEEE 754 floating point numbers are supported with {{rust|f32}} for single precision floats and {{rust|f64}} for double precision floats.{{sfn|Klabnik|Nichols|2019|pp=38–40}}

== User-defined types ==

User-defined types are created with the {{rust|struct}} or {{rust|enum}} keywords. The {{rust|struct}} keyword is used to denote a record type that groups multiple related values.{{sfn|Klabnik|Nichols|2019|p=83}} {{rust|enum}}s can take on different variants at runtime, with its capabilities similar to algebraic data types found in functional programming languages.{{sfn|Klabnik|Nichols|2019|p=97}} Both records and enum variants can contain fields with different types.{{sfn|Klabnik|Nichols|2019|pp=98–101}} Alternative names, or aliases, for the same type can be defined with the {{rust|type}} keyword.{{sfn|Klabnik|Nichols|2019|pp=438–440}}

The {{rust|impl}} keyword can define methods for a user-defined type. Data and functions are defined separately. Implementations fulfill a role similar to that of classes within other languages.{{sfn|Klabnik|Nichols|2019|pp=93}}

== Standard library ==

class="wikitable"

|+Summary of Rust's types in the standard library

!Type

!Description

!Examples

{{Rust|String}}

|UTF-8-encoded strings (dynamic)

|{{plainlist|

  • {{Rust|String::new()}}
  • {{Rust|String::from("Hello")}}
  • {{Rust|"🦀🦀🦀".to_string()}}

}}

{{plainlist|

  • {{Rust|OsStr}}
  • {{Rust|OsString}}

}}

|Platform-native stringsOn Unix systems, this is often UTF-8 strings without an internal 0 byte. On Windows, this is UTF-16 strings without an internal 0 byte. Unlike these, {{Rust|str}} and {{Rust|String}} are always valid UTF-8 and can contain internal zeros. (borrowed{{Cite web |title=OsStr in std::ffi |url=https://doc.rust-lang.org/beta/std/ffi/struct.OsStr.html |access-date=2023-10-02 |website=The Rust Standard Library documentation |archive-date=2023-06-23 |archive-url=https://web.archive.org/web/20230623184907/https://doc.rust-lang.org/beta/std/ffi/struct.OsStr.html |url-status=live }} and dynamic{{Cite web |title=OsString in std::ffi |url=https://doc.rust-lang.org/beta/std/ffi/struct.OsString.html |access-date=2023-10-02 |website=The Rust Standard Library documentation |archive-date=2023-06-24 |archive-url=https://web.archive.org/web/20230624103428/https://doc.rust-lang.org/beta/std/ffi/struct.OsString.html |url-status=live }})

|{{plainlist|

  • {{Rust|OsStr::new("Hello")}}
  • {{Rust|OsString::from("world")}}

}}

{{plainlist|

  • {{Rust|Path}}
  • {{Rust|PathBuf}}

}}

|Paths (borrowed{{Cite web |title=Path in std::path |url=https://doc.rust-lang.org/beta/std/path/struct.Path.html |access-date=2023-10-02 |website=The Rust Standard Library documentation |archive-date=2023-06-24 |archive-url=https://web.archive.org/web/20230624103428/https://doc.rust-lang.org/beta/std/path/struct.Path.html |url-status=live }} and dynamic{{Cite web |title=PathBuf in std::path |url=https://doc.rust-lang.org/beta/std/path/struct.PathBuf.html |access-date=2023-10-02 |website=The Rust Standard Library documentation |archive-date=2023-06-27 |archive-url=https://web.archive.org/web/20230627034115/https://doc.rust-lang.org/beta/std/path/struct.PathBuf.html |url-status=live }})

|{{plainlist|

  • {{Rust|Path::new("./path/to")}}
  • {{Rust|PathBuf::from(r"C:.\path\to")}}

}}

{{plainlist|

  • {{Rust|CStr}}
  • {{Rust|CString}}

}}

|C-compatible, null-terminated strings (borrowed{{Cite web |title=std::boxed |url=https://doc.rust-lang.org/std/boxed/index.html |access-date=2023-06-23 |website=The Rust Standard Library documentation |archive-date=2023-06-23 |archive-url=https://web.archive.org/web/20230623184904/https://doc.rust-lang.org/std/boxed/index.html |url-status=live }} and dynamic)

|{{plainlist|

  • {{Rust|c"Hello"}}
  • {{Rust|CStr::from_bytes_with_nul(b"Hello\0").unwrap()}}
  • {{Rust|CString::new("world").unwrap()}}

}}

{{Rust|Vec}}

|Dynamic arrays

|{{plainlist|

  • {{Rust|Vec::new()}}
  • {{Rust|vec![1, 2, 3, 4, 5]}}

}}

{{Rust|Option}}

|Option type

|{{plainlist|

  • {{Rust|None}}
  • {{Rust|Some(3)}}
  • {{Rust|Some("hello")}}

}}

{{Rust|Result}}

|Error handling using a result type

|{{plainlist|

  • {{Rust|Ok(3)}}
  • {{Rust|Err("something went wrong")}}

}}

{{Rust|Box}}

|A pointer to a heap-allocated value. Similar to C++'s [https://en.cppreference.com/w/cpp/memory/unique_ptr std::unique_ptr].

|

let boxed: Box = Box::new(5);

let val: u8 = *boxed;

{{Rust|Rc}}

|Reference counting pointer{{Cite web |title=Rc in std::rc |url=https://doc.rust-lang.org/beta/std/rc/struct.Rc.html |access-date=2023-06-24 |website=The Rust Standard Library documentation |archive-date=2023-06-24 |archive-url=https://web.archive.org/web/20230624080501/https://doc.rust-lang.org/beta/std/rc/struct.Rc.html |url-status=live }}

|

let five = Rc::new(5);

let also_five = five.clone();

{{Rust|Arc}}

|Atomic, thread-safe reference counting pointer{{Cite web |title=Arc in std::sync |url=https://doc.rust-lang.org/beta/std/sync/struct.Arc.html |access-date=2023-06-24 |website=The Rust Standard Library documentation |archive-date=2023-06-24 |archive-url=https://web.archive.org/web/20230624080503/https://doc.rust-lang.org/beta/std/sync/struct.Arc.html |url-status=live }}

|

let foo = Arc::new(vec![1.0, 2.0]);

let a = foo.clone(); // a can be sent to another thread

{{Rust|Cell}}

|A mutable memory location{{Cite web |title=Cell in std::cell |url=https://doc.rust-lang.org/beta/std/cell/struct.Cell.html |access-date=2023-06-24 |website=The Rust Standard Library documentation |archive-date=2023-06-24 |archive-url=https://web.archive.org/web/20230624080506/https://doc.rust-lang.org/beta/std/cell/struct.Cell.html |url-status=live }}

|

let c = Cell::new(5);

c.set(10);

Mutex

|A mutex lock for shared data contained within.{{Cite web |title=Mutex in std::sync |url=https://doc.rust-lang.org/beta/std/sync/struct.Mutex.html |access-date=2023-06-24 |website=The Rust Standard Library documentation |archive-date=2023-06-24 |archive-url=https://web.archive.org/web/20230624080502/https://doc.rust-lang.org/beta/std/sync/struct.Mutex.html |url-status=live }}

|

let mutex = Mutex::new(0_u32);

let _guard = mutex.lock();

{{Rust|RwLock}}

|Readers–writer lock{{Cite web |title=RwLock in std::sync |url=https://doc.rust-lang.org/beta/std/sync/struct.RwLock.html |access-date=2023-06-24 |website=The Rust Standard Library documentation |archive-date=2023-06-24 |archive-url=https://web.archive.org/web/20230624080503/https://doc.rust-lang.org/beta/std/sync/struct.RwLock.html |url-status=live }}

|

let lock = RwLock::new(5);

let r1 = lock.read().unwrap();

{{Rust|Condvar}}

|A conditional monitor for shared data{{Cite web |title=Condvar in std::sync |url=https://doc.rust-lang.org/beta/std/sync/struct.Condvar.html |access-date=2023-06-24 |website=The Rust Standard Library documentation |archive-date=2023-06-24 |archive-url=https://web.archive.org/web/20230624080504/https://doc.rust-lang.org/beta/std/sync/struct.Condvar.html |url-status=live }}

|

let (lock, cvar) = (Mutex::new(true), Condvar::new());

// As long as the value inside the `Mutex` is `true`, we wait.

let _guard = cvar.wait_while(lock.lock().unwrap(), |pending| { *pending }).unwrap();

{{Rust|Duration}}

|Type that represents a span of time{{Cite web |title=Duration in std::time |url=https://doc.rust-lang.org/beta/std/time/struct.Duration.html |access-date=2023-06-24 |website=The Rust Standard Library documentation |archive-date=2023-06-24 |archive-url=https://web.archive.org/web/20230624080503/https://doc.rust-lang.org/beta/std/time/struct.Duration.html |url-status=live }}

|

Duration::from_millis(1) // 1ms

{{Rust|1=HashMap}}

|Hash table{{Cite web |title=HashMap in std::collections |url=https://doc.rust-lang.org/beta/std/collections/struct.HashMap.html |access-date=2023-06-24 |website=The Rust Standard Library documentation |archive-date=2023-06-24 |archive-url=https://web.archive.org/web/20230624080505/https://doc.rust-lang.org/beta/std/collections/struct.HashMap.html |url-status=live }}

|

let mut player_stats = HashMap::new();

player_stats.insert("damage", 1);

player_stats.entry("health").or_insert(100);

{{Rust|1=BTreeMap}}

|B-tree{{Cite web |title=BTreeMap in std::collections |url=https://doc.rust-lang.org/beta/std/collections/struct.BTreeMap.html |access-date=2023-06-24 |website=The Rust Standard Library documentation |archive-date=2023-06-24 |archive-url=https://web.archive.org/web/20230624080503/https://doc.rust-lang.org/beta/std/collections/struct.BTreeMap.html |url-status=live }}

|

let mut solar_distance = BTreeMap::from([

("Mercury", 0.4),

("Venus", 0.7),

]);

solar_distance.entry("Earth").or_insert(1.0);

Option values are handled using syntactic sugar, such as the if let construction, to access the inner value (in this case, a string):{{sfn|McNamara|2021}}

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 ==

class="wikitable"

|+Summary of Rust's pointer and reference primitive types

!Type

!Description

!Examples

{{plainlist|

  • {{Rust|&T}}
  • {{Rust|&mut T}}

}}

|References (immutable and mutable)

|{{plainlist|

  • {{Rust|let x_ref {{=}} {{not a typo|&x;}}}}
  • {{Rust|let x_ref {{=}} &mut x;}}

}}

{{plainlist|

  • {{Rust|Option<&T>}}
  • {{Rust|Option<&mut T>}}

}}

|{{plainlist|

  • Option wrapped reference
  • Possibly null reference

}}

|{{plainlist|

  • {{Rust|None}}
  • {{Rust|let x_ref {{=}} Some(&x);}}
  • {{Rust|let x_ref {{=}} Some(&mut x);}}

}}

{{Plain list|* {{Rust|Box}}

  • {{Rust|Option>}}}}

|A pointer to heap-allocated value

(or possibly null pointer if wrapped in option)

|{{Plain list|* {{Rust|let boxed {{=}} Box::new(0);}}

  • {{Rust|let boxed {{=}} Some(Box::new("Hello World"));}}}}
{{Plainlist|
  • {{Rust|*const T}}
  • {{Rust|*mut T}}
  • }}

    |{{Plainlist|

    • Raw pointers (immutable and mutable)
    • Possibly null; {{Rust|unsafe}} to dereference

    }}

    |{{Plainlist|

    • {{Rust|let x_ptr {{=}} &x as *const T;}}
    • {{Rust|let x_ptr {{=}} &mut x as *mut T;}}

    }}

    Rust does not use null pointers to indicate a lack of data, as doing so can lead to null dereferencing. Accordingly, the basic & and &mut references are guaranteed to not be null. Rust instead uses Option for this purpose: Some(T) indicates that a value is present, and None is analogous to the null pointer.{{sfn|Klabnik|Nichols|2019|pp=101–104}} Option implements a "null pointer optimization", avoiding any spatial overhead for types that cannot have a null value (references or the NonZero types, for example).{{Cite web |title=std::option |url=https://doc.rust-lang.org/std/option/index.html#representation |access-date=2023-11-12 |website=The Rust Standard Library documentation}}

    Unlike references, the raw pointer types *const and *mut may be null; however, it is impossible to dereference them unless the code is explicitly declared unsafe through the use of an unsafe block. Unlike dereferencing, the creation of raw pointers is allowed inside of safe Rust code.{{sfn|Klabnik|Nichols|2019|pp=418–427}}

    == Type conversion ==

    {{excerpt|Type conversion|Rust}}

    = Ownership =

    Rust's ownership system consists of rules that ensure memory safety without using a garbage collector. At compile time, each value must be attached to a variable called the owner of that value, and every value must have exactly one owner.{{sfn|Klabnik|Nichols|2019|pp=59–61}} Values are moved between different owners through assignment or passing a value as a function parameter. Values can also be borrowed, meaning they are temporarily passed to a different function before being returned to the owner.{{sfn|Klabnik|Nichols|2019|pp=63–68}} With these rules, Rust can prevent the creation and use of dangling pointers:{{sfn|Klabnik|Nichols|2019|pp=63–68}}{{sfn|Klabnik|Nichols|2019|pp=74–75}}

    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

    }

    Because of these ownership rules, Rust types are known as linear or affine types, meaning each value can be used exactly once. This enforces a form of software fault isolation as the owner of a value is solely responsible for its correctness and deallocation.{{Cite book |last1=Balasubramanian |first1=Abhiram |last2=Baranowski |first2=Marek S. |last3=Burtsev |first3=Anton |last4=Panda |first4=Aurojit |last5=Rakamarić |first5=Zvonimir |last6=Ryzhyk |first6=Leonid |title=Proceedings of the 16th Workshop on Hot Topics in Operating Systems |chapter=System Programming in Rust |date=2017-05-07 |chapter-url=https://doi.org/10.1145/3102980.3103006 |series=HotOS '17 |location=New York, NY, US |publisher=Association for Computing Machinery |pages=156–161 |doi=10.1145/3102980.3103006 |isbn=978-1-4503-5068-6 |s2cid=24100599 |access-date=June 1, 2022 |archive-date=June 11, 2022 |archive-url=https://web.archive.org/web/20220611034046/https://dl.acm.org/doi/10.1145/3102980.3103006 |url-status=live}}

    When a value goes out of scope, it is dropped by running its destructor. The destructor may be programmatically defined through implementing the {{code|Drop}} trait. This helps manage resources such as file handles, network sockets, and locks, since when objects are dropped, the resources associated with them are closed or released automatically.{{sfn|Klabnik|Nichols|2023|pp=327-30}}

    = Lifetimes =

    Object lifetime refers to the period of time during which a reference is valid; that is, the time between the object creation and destruction.{{Cite web |title=Lifetimes |url=https://doc.rust-lang.org/rust-by-example/scope/lifetime.html |access-date=2024-10-29 |website=Rust by Example |archive-date=2024-11-16 |archive-url=https://web.archive.org/web/20241116192422/https://doc.rust-lang.org/rust-by-example/scope/lifetime.html |url-status=live }} These lifetimes are implicitly associated with all Rust reference types. While often inferred, they can also be indicated explicitly with named lifetime parameters (often denoted {{code|'a}}, {{code|'b}}, and so on).{{Cite web |title=Explicit annotation |url=https://doc.rust-lang.org/rust-by-example/scope/lifetime/explicit.html |access-date=2024-10-29 |website=Rust by Example}}

    Lifetimes in Rust can be thought of as lexically scoped, meaning that the duration of an object lifetime is inferred from the set of locations in the source code (i.e., function, line, and column numbers) for which a variable is valid.{{sfn|Klabnik|Nichols|2019|p=194}} For example, a reference to a local variable has a lifetime corresponding to the block it is defined in:{{sfn|Klabnik|Nichols|2019|p=194}}

    fn main() {

    let x = 5; // ------------------+- Lifetime 'a

    // |

    let r = &x; // -+-- Lifetime 'b |

    // | |

    println!("r: {}", r); // | |

    // | |

    // -+ |

    } // ------------------+

    The borrow checker in the Rust compiler then enforces that references are only used in the locations of the source code where the associated lifetime is valid.{{sfn|Klabnik|Nichols|2019|pp=75,134}}{{Cite web |last=Shamrell-Harrington |first=Nell |date=2022-04-15 |title=The Rust Borrow Checker – a Deep Dive |url=https://www.infoq.com/presentations/rust-borrow-checker/ |access-date=2022-06-25 |website=InfoQ |language=en |archive-date=2022-06-25 |archive-url=https://web.archive.org/web/20220625140128/https://www.infoq.com/presentations/rust-borrow-checker/ |url-status=live }} In the example above, storing a reference to variable {{code|x}} in {{code|r}} is valid, as variable {{code|x}} has a longer lifetime ({{code|'a}}) than variable {{code|r}} ({{code|'b}}). However, when {{code|x}} has a shorter lifetime, the borrow checker would reject the program:

    fn main() {

    let r; // ------------------+- Lifetime 'a

    // |

    { // |

    let x = 5; // -+-- Lifetime 'b |

    r = &x; // | | // ERROR here: x does not live long enough

    } // -| |

    // |

    println!("r: {}", r); // |

    } // ------------------+

    Since the lifetime of the referenced variable ({{code|'b}}) is shorter than the lifetime of the variable holding the reference ({{code|'a}}), the borrow checker errors, preventing {{code|x}} from being used from outside its scope.{{sfn|Klabnik|Nichols|2019|pp=194-195}}

    Lifetimes can be indicated using explicit lifetime parameters on function arguments. For example, the following code specifies that the reference returned by the function has the same lifetime as {{code|original}} (and not necessarily the same lifetime as {{code|prefix}}):{{sfn|Klabnik|Nichols|2023|pp=208–12}}

    fn remove_prefix<'a>(mut original: &'a str, prefix: &str) -> &'a str {

    if original.starts_with(prefix) {

    original = original[prefix.len()..];

    }

    original

    }

    When user-defined types hold references to data, they also need to use lifetime parameters. The example below parses some configuration options from a string and creates a struct containing the options. The function parse_config also showcases lifetime elision, which reduces the need for explicitly defining lifetime parameters.{{sfn|Klabnik|Nichols|2019|pp=201–203}}

    use std::collections::HashMap;

    // This struct has one lifetime parameter, 'src. The name is only used within the struct's definition.

    1. [derive(Debug)]

    struct Config<'src> {

    hostname: &'src str,

    username: &'src str,

    }

    // The '_ lifetime parameter, in this case, refers to the anonymous lifetime attached to the type

    // of the argument `config`.

    fn parse_config(config: &str) -> Config<'_> {

    let key_values: HashMap<_, _> = config

    .lines()

    .filter(|line| !line.starts_with('#'))

    .filter_map(|line| line.split_once('='))

    .map(|(key, value)| (key.trim(), value.trim()))

    .collect();

    Config {

    hostname: key_values["hostname"],

    username: key_values["username"],

    }

    }

    fn main() {

    let config = parse_config(

    r#"hostname = foobar

    username=barfoo"#,

    );

    println!("Parsed config: {:#?}", config);

    }

    In the compiler, ownership and lifetimes work together to prevent memory safety issues such as dangling pointers.{{sfn|Klabnik|Nichols|2023|loc=[https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html 4.2. References and Borrowing]}}{{cite journal |last1=Pearce |first1=David |title=A Lightweight Formalism for Reference Lifetimes and Borrowing in Rust |url=https://dl.acm.org/doi/10.1145/3443420 |journal=ACM Transactions on Programming Languages and Systems |access-date=11 December 2024 |archive-url=https://web.archive.org/web/20240415053627/https://dl.acm.org/doi/10.1145/3443420 |archive-date=15 April 2024 |doi=10.1145/3443420 |date=17 April 2021 |volume=43 |pages=1–73 |url-status=live}}

    File:Rust 101.webm's Rust team (linux.conf.au conference, Hobart, 2017)]]

    = Polymorphism =

    == Generics ==

    Rust's more advanced features include the use of generic functions. A generic function is given generic parameters, which allow the same function to be applied to different variable types. This capability reduces duplicate code{{sfn|Klabnik|Nichols|2019|pp=171–172}} and is known as parametric polymorphism.

    The following program calculates the sum of two things, for which addition is implemented using a generic function:

    use std::ops::Add;

    // sum is a generic function with one type parameter, T

    fn sum(num1: T, num2: T) -> T

    where

    T: Add, // T must implement the Add trait where addition returns another T

    {

    num1 + num2 // num1 + num2 is syntactic sugar for num1.add(num2) provided by the Add trait

    }

    fn main() {

    let result1 = sum(10, 20);

    println!("Sum is: {}", result1); // Sum is: 30

    let result2 = sum(10.23, 20.45);

    println!("Sum is: {}", result2); // Sum is: 30.68

    }

    At compile time, polymorphic functions like sum are instantiated with the specific types the code requires; in this case, sum of integers and sum of floats.

    Generics can be used in functions to allow implementing a behavior for different types without repeating the same code. Generic functions can be written in relation to other generics, without knowing the actual type.{{sfn|Klabnik|Nichols|2019|pp=171–172,205}}

    == Traits ==

    File:UML class diagram Rust stdio.svg

    Rust's type system supports a mechanism called traits, inspired by type classes in the Haskell language, to define shared behavior between different types. For example, the Add trait can be implemented for floats and integers, which can be added; and the Display or Debug traits can be implemented for any type that can be converted to a string. Traits can be used to provide a set of common behavior for different types without knowing the actual type. This facility is known as ad hoc polymorphism.

    Generic functions can constrain the generic type to implement a particular trait or traits; for example, an add_one function might require the type to implement Add. This means that a generic function can be type-checked as soon as it is defined. The implementation of 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 via the keyword dyn (short for dynamic).{{sfn|Klabnik|Nichols|2019|pp=181,182}} Because monomorphization duplicates the code for each type used, it can result in more optimized code for specific-use cases, but compile time and size of the output binary are also increased.{{sfn|Gjengset|2021|p=25}}

    In addition to defining methods for a user-defined type, the impl keyword can be used to implement a trait for a type.{{sfn|Klabnik|Nichols|2019|pp=93}} Traits can provide additional derived methods when implemented.{{sfn|Klabnik|Nichols|2019|pp=182–184}} For example, the trait Iterator requires that the next method be defined for the type. Once the next method is defined, the trait can provide common functional helper methods over the iterator, such as map or filter.{{sfn|Klabnik|Nichols|2019|pp=281–283}}

    == Trait objects ==

    Rust traits are implemented using static dispatch, meaning that the type of all values is known at compile time; however, Rust also uses a feature known as trait objects to accomplish dynamic dispatch, a type of polymorphism where the implementation of a polymorphic operation is chosen at runtime. This allows for behavior similar to duck typing, where all data types that implement a given trait can be treated as functionally equivalent.{{sfn|Klabnik|Nichols|2023|loc=[https://doc.rust-lang.org/book/ch18-02-trait-objects.html 18.2. Using Trait Objects That Allow for Values of Different Types]}} Trait objects are declared using the syntax dyn Tr where Tr is a trait. Trait objects are dynamically sized, therefore they must be put behind a pointer, such as Box.{{sfn|Klabnik|Nichols|2019|pp=441–442}} The following example creates a list of objects where each object can be printed out using the Display trait:

    use std::fmt::Display;

    let v: Vec> = vec![

    Box::new(3),

    Box::new(5.0),

    Box::new("hi"),

    ];

    for x in v {

    println!("{x}");

    }

    If an element in the list does not implement the Display trait, it will cause a compile-time error.{{sfn|Klabnik|Nichols|2019|pp=379–380}}

    = Memory safety =

    Rust is designed to be memory safe. It does not permit null pointers, dangling pointers, or data races.{{cite web |url=http://reviews.cnet.com/8301-3514_7-57577639/samsung-joins-mozillas-quest-for-rust/ |title=Samsung joins Mozilla's quest for Rust |last=Rosenblatt |first=Seth |date=2013-04-03 |publisher=CNET |access-date=2013-04-05 |archive-date=2013-04-04 |archive-url=https://web.archive.org/web/20130404142333/http://reviews.cnet.com/8301-3514_7-57577639/samsung-joins-mozillas-quest-for-rust/ |url-status=live}}{{cite web |last=Brown |first=Neil |date=2013-04-17 |title=A taste of Rust |url=https://lwn.net/Articles/547145/ |url-status=live |archive-url=https://web.archive.org/web/20130426010754/http://lwn.net/Articles/547145/ |archive-date=2013-04-26 |access-date=2013-04-25 |website=LWN.net}}{{Cite web|url=https://doc.rust-lang.org/nomicon/races.html|title=Races|website=The Rustonomicon|access-date=2017-07-03|archive-date=2017-07-10|archive-url=https://web.archive.org/web/20170710194643/https://doc.rust-lang.org/nomicon/races.html|url-status=live}}{{cite journal |last1=Vandervelden |first1=Thibaut |last2=De Smet |first2=Ruben |last3=Deac |first3=Diana |last4=Steenhaut |first4=Kris |last5=Braeken |first5=An |title=Overview of Embedded Rust Operating Systems and Frameworks |journal= Sensors|doi=10.3390/s24175818 |date=7 September 2024 |volume=24 |issue=17 |page=5818 |doi-access=free |pmid=39275729 |pmc=11398098 |bibcode=2024Senso..24.5818V }} Data values can be initialized only through a fixed set of forms, all of which require their inputs to be already initialized.{{cite web |title=The Rust Language FAQ |publisher=The Rust Programming Language |url=http://static.rust-lang.org/doc/master/complement-lang-faq.html |url-status=dead |archive-url=https://web.archive.org/web/20150420104147/http://static.rust-lang.org/doc/master/complement-lang-faq.html |archive-date=2015-04-20 |year=2015 |access-date=2017-04-24}}

    Unsafe code can subvert some of these restrictions, using the unsafe keyword.{{sfn|Klabnik|Nichols|2019|pp=418–427}} Unsafe code may also be used for low-level functionality, such as volatile memory access, architecture-specific intrinsics, type punning, and inline assembly.{{sfn|McNamara|2021|p=139, 376–379, 395}}

    = Memory management =

    Rust does not use garbage collection. Memory and other resources are instead managed through the "resource acquisition is initialization" convention,{{Cite web|title=RAII|url=https://doc.rust-lang.org/rust-by-example/scope/raii.html|access-date=2020-11-22|website=Rust by Example|archive-date=2019-04-21|archive-url=https://web.archive.org/web/20190421131142/https://doc.rust-lang.org/rust-by-example/scope/raii.html|url-status=live}} with optional reference counting. Rust provides deterministic management of resources, with very low overhead.{{Cite web|url=https://blog.rust-lang.org/2015/05/11/traits.html|title=Abstraction without overhead: traits in Rust|website=Rust Blog|access-date=October 19, 2021|archive-date=September 23, 2021|archive-url=https://web.archive.org/web/20210923101530/https://blog.rust-lang.org/2015/05/11/traits.html|url-status=live}} Values are allocated on the stack by default, and all dynamic allocations must be explicit.{{Cite web |title=Box, stack and heap |url=https://doc.rust-lang.org/stable/rust-by-example/std/box.html |access-date=2022-06-13 |website=Rust by Example |archive-date=2022-05-31 |archive-url=https://web.archive.org/web/20220531114141/https://doc.rust-lang.org/stable/rust-by-example/std/box.html |url-status=live }}

    The built-in reference types using the & symbol do not involve run-time reference counting. The safety and validity of the underlying pointers is verified at compile time, preventing dangling pointers and other forms of undefined behavior.{{sfn|Klabnik|Nichols|2019|pp=70–75}} Rust's type system separates shared, immutable references of the form &T from unique, mutable references of the form &mut T. A mutable reference can be coerced to an immutable reference, but not vice versa.{{sfn|Klabnik|Nichols|2019|p=323}}

    = Macros =

    Macros allow generation and transformation of Rust code to reduce repetition. Macros come in two forms, with declarative macros defined through macro_rules!, and procedural macros, which are defined in separate crates.{{sfn|Klabnik|Nichols|2023|pp=449–455}}{{sfn|Gjengset|2021|pp=101-102}}

    == Declarative macros ==

    A declarative macro (also called a "macro by example") is a macro, defined using the macro_rules! keyword, that uses pattern matching to determine its expansion.{{cite web |title=Macros By Example |url=https://doc.rust-lang.org/reference/macros-by-example.html |website=The Rust Reference |access-date=21 April 2023 |archive-date=2023-04-21 |archive-url=https://web.archive.org/web/20230421052332/https://doc.rust-lang.org/reference/macros-by-example.html |url-status=live }}{{sfn|Klabnik|Nichols|2019|pp=446–448}} Below is an example that sums over all its arguments:

    macro_rules! sum {

    ( $initial:expr $(, $expr:expr )* $(,)? ) => {

    $initial $(+ $expr)*

    }

    }

    fn main() {

    let x = sum!(1, 2, 3);

    println!("{x}"); // prints 6

    }

    == Procedural macros ==

    Procedural macros are Rust functions that run and modify the compiler's input token stream, before any other components are compiled. They are generally more flexible than declarative macros, but are more difficult to maintain due to their complexity.{{cite web |url=https://doc.rust-lang.org/reference/procedural-macros.html |title=Procedural Macros |website=The Rust Programming Language Reference |access-date=23 Mar 2021 |archive-date=7 November 2020 |archive-url=https://web.archive.org/web/20201107233444/https://doc.rust-lang.org/reference/procedural-macros.html |url-status=live}}{{sfn|Klabnik|Nichols|2019|pp=449–455}}

    Procedural macros come in three flavors:

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

    = Interface with C and C++ =

    Rust has a foreign function interface (FFI) that can be used both to call code written in languages such as C from Rust and to call Rust code from those languages. {{As of|2024}}, an external library called CXX exists for calling to or from C++.{{Cite web|title=Safe Interoperability between Rust and C++ with CXX|url=https://www.infoq.com/news/2020/12/cpp-rust-interop-cxx/|date=2020-12-06|access-date=2021-01-03|website=InfoQ|language=en|archive-date=January 22, 2021|archive-url=https://web.archive.org/web/20210122142035/https://www.infoq.com/news/2020/12/cpp-rust-interop-cxx/|url-status=live}} Rust and C differ in how they lay out structs in memory, so Rust structs may be given a #[repr(C)] attribute, forcing the same layout as the equivalent C struct.{{cite web |title=Type layout |url=https://doc.rust-lang.org/reference/type-layout.html#the-c-representation |website=The Rust Reference |access-date=15 July 2022 |archive-date=2022-07-16 |archive-url=https://web.archive.org/web/20220716021840/https://doc.rust-lang.org/reference/type-layout.html#the-c-representation |url-status=live }}

    Ecosystem

    File:Cargo compiling.webm

    The Rust ecosystem includes its compiler, its standard library, and additional components for software development. Component installation is typically managed by {{code|rustup}}, a Rust toolchain installer developed by the Rust project.{{sfn|Blandy|Orendorff|Tindall|2021|pp=6-8}}

    = Compiler =

    The Rust compiler, {{code|rustc}}, translates Rust code into low-level LLVM IR. LLVM is then invoked as a subcomponent to apply optimizations and translate the resulting IR into object code. A linker is then used to combine the objects into a single executable image or binary file.{{cite web |title=Overview of the compiler |url=https://rustc-dev-guide.rust-lang.org/overview.html |website=Rust Compiler Development Guide |publisher=Rust project contributors |access-date=7 November 2024 |archive-date=2023-05-31 |archive-url=https://web.archive.org/web/20230531035222/https://rustc-dev-guide.rust-lang.org/overview.html |url-status=live }}

    Other than LLVM, the compiler also supports using alternative backends such as GCC and Cranelift for code generation.{{cite web |title=Code Generation |url=https://rustc-dev-guide.rust-lang.org/backend/codegen.html |website=Rust Compiler Development Guide |publisher=Rust project contributors |access-date=3 March 2024}} The intention of those alternative backends is to increase platform coverage of Rust or to improve compilation times.{{cite web |title=rust-lang/rustc_codegen_gcc |url=https://github.com/rust-lang/rustc_codegen_gcc#Motivation |website=GitHub |publisher=The Rust Programming Language |access-date=3 March 2024 |date=2 March 2024}}{{cite web |title=rust-lang/rustc_codegen_cranelift |url=https://github.com/rust-lang/rustc_codegen_cranelift |website=GitHub |publisher=The Rust Programming Language |access-date=3 March 2024 |date=2 March 2024}}

    = Standard library =

    The Rust standard library defines and implements many widely used custom data types, including core data structures such as {{code|Vec}}, {{code|Option}}, and {{code|HashMap}}, as well as smart pointer types. Rust also provides a way to exclude most of the standard library using the attribute {{rust|#![no_std]}}; this enables applications, such as embedded devices, which want to remove dependency code or provide their own core data structures. Internally, the standard library is divided into three parts, {{code|core}}, {{code|alloc}}, and {{code|std}}, where {{code|std}} and {{Code|alloc}} are excluded by {{rust|#![no_std]}}.{{sfn|Gjengset|2021|p=213-215}}

    File:Crates.io website.png

    = Cargo =

    Cargo is Rust's build system and package manager. It downloads, compiles, distributes, and uploads packages—called crates—that are maintained in an official registry. It also acts as a front-end for Clippy and other Rust components.{{Cite journal |last=Perkel |first=Jeffrey M. |date=2020-12-01 |title=Why scientists are turning to Rust |url=https://www.nature.com/articles/d41586-020-03382-2 |journal=Nature |language=en |volume=588 |issue=7836 |pages=185–186 |doi=10.1038/d41586-020-03382-2 |pmid=33262490 |bibcode=2020Natur.588..185P |s2cid=227251258 |access-date=May 15, 2022 |archive-date=May 6, 2022 |archive-url=https://web.archive.org/web/20220506040523/https://www.nature.com/articles/d41586-020-03382-2 |url-status=live}}

    By default, Cargo sources its dependencies from the user-contributed registry crates.io, but Git repositories, crates in the local filesystem, and other external sources can also be specified as dependencies.{{Cite web |last=Simone |first=Sergio De |date=2019-04-18 |title=Rust 1.34 Introduces Alternative Registries for Non-Public Crates |url=https://www.infoq.com/news/2019/04/rust-1.34-additional-registries |access-date=2022-07-14 |website=InfoQ |language=en |archive-date=2022-07-14 |archive-url=https://web.archive.org/web/20220714164454/https://www.infoq.com/news/2019/04/rust-1.34-additional-registries |url-status=live }}

    = Rustfmt =

    Rustfmt is a code formatter for Rust. It formats whitespace and indentation to produce code in accordance with a common style, unless otherwise specified. It can be invoked as a standalone program, or from a Rust project through Cargo.{{sfn|Klabnik|Nichols|2019|pp=511–512}}

    File:Cargo clippy hello world example.png

    = Clippy =

    Clippy is Rust's built-in linting tool to improve the correctness, performance, and readability of Rust code. {{as of|2024}}, it has more than 700 rules.{{Cite web |title=Clippy |date=2023-11-30 |url=https://github.com/rust-lang/rust-clippy |access-date=2023-11-30 |website=GitHub |publisher=The Rust Programming Language |archive-date=2021-05-23 |archive-url=https://web.archive.org/web/20210523042004/https://github.com/rust-lang/rust-clippy |url-status=live }}{{Cite web |title=Clippy Lints |url=https://rust-lang.github.io/rust-clippy/master/index.html |access-date=2023-11-30 |website=The Rust Programming Language}}

    = Versioning system =

    Following Rust 1.0, new features are developed in nightly versions which are released daily. During each six-week release cycle, changes to nightly versions are released to beta, while changes from the previous beta version are released to a new stable version.{{harvnb|Klabnik|Nichols|2019|loc=Appendix G – How Rust is Made and "Nightly Rust"}}

    Every two or three years, a new "edition" is produced. Editions are released to allow making limited breaking changes, such as promoting {{code|await}} to a keyword to support async/await features. Crates targeting different editions can interoperate with each other, so a crate can upgrade to a new edition even if its callers or its dependencies still target older editions. Migration to a new edition can be assisted with automated tooling.{{sfn|Blandy|Orendorff|Tindall|2021|pp=176–177}}

    = IDE support =

    rust-analyzer is a collection of utilities that provides Integrated development environments (IDEs) and text editors with information about a Rust project through the Language Server Protocol. This enables features including autocompletion, and the display of compilation errors while editing.{{sfn|Klabnik|Nichols|2023|p=623}}

    Performance

    Since it performs no garbage collection, Rust is often faster than other memory-safe languages.{{Cite web |last1=Anderson |first1=Tim |date=2021-11-30 |title=Can Rust save the planet? Why, and why not |url=https://www.theregister.com/2021/11/30/aws_reinvent_rust/ |access-date=2022-07-11 |website=The Register |language=en |archive-date=2022-07-11 |archive-url=https://web.archive.org/web/20220711001629/https://www.theregister.com/2021/11/30/aws_reinvent_rust/ |url-status=live}}{{Cite web |last1=Yegulalp |first1=Serdar |date=2021-10-06 |title=What is the Rust language? Safe, fast, and easy software development |url=https://www.infoworld.com/article/3218074/what-is-rust-safe-fast-and-easy-software-development.html |access-date=2022-06-25 |website=InfoWorld |language=en |archive-date=2022-06-24 |archive-url=https://web.archive.org/web/20220624101013/https://www.infoworld.com/article/3218074/what-is-rust-safe-fast-and-easy-software-development.html |url-status=live}} Most of Rust's memory safety guarantees impose no runtime overhead,{{sfn|McNamara|2021|p=11}} with the exception of array indexing which is checked at runtime by default.{{Cite journal |last1=Popescu |first1=Natalie |last2=Xu |first2=Ziyang |last3=Apostolakis |first3=Sotiris |last4=August |first4=David I. |last5=Levy |first5=Amit |date=2021-10-15 |title=Safer at any speed: automatic context-aware safety enhancement for Rust |journal=Proceedings of the ACM on Programming Languages |volume=5 |issue=OOPSLA |quote="We observe a large variance in the overheads of checked indexing: 23.6% of benchmarks do report significant performance hits from checked indexing, but 64.5% report little-to-no impact and, surprisingly, 11.8% report improved performance ... Ultimately, while unchecked indexing can improve performance, most of the time it does not." |quote-page=5 |at=Section 2 |doi=10.1145/3485480 |s2cid=238212612|doi-access=free}} Performance impact of array indexing bounds checks varies, but can be significant in some cases.

    Rust provides two "modes": safe and unsafe. Safe mode is the "normal" one, in which most Rust is written. In unsafe mode, the developer is responsible for the code's memory safety, which is used by developers for cases where the compiler is too restrictive.{{Cite journal |last1=Astrauskas |first1=Vytautas |last2=Matheja |first2=Christoph |last3=Poli |first3=Federico |last4=Müller |first4=Peter |last5=Summers |first5=Alexander J. |date=2020-11-13 |title=How do programmers use unsafe rust? |url=https://dl.acm.org/doi/10.1145/3428204 |journal=Proceedings of the ACM on Programming Languages |language=en |volume=4 |issue=OOPSLA |pages=1–27 |doi=10.1145/3428204 |issn=2475-1421|hdl=20.500.11850/465785 |hdl-access=free}}

    Many of Rust's features are so-called zero-cost abstractions, meaning they are optimized away at compile time and incur no runtime penalty.{{sfn|McNamara|2021|p=19, 27}} The ownership and borrowing system permits zero-copy implementations for some performance-sensitive tasks, such as parsing.{{Cite book |last=Couprie |first=Geoffroy |title=2015 IEEE Security and Privacy Workshops |chapter=Nom, A Byte oriented, streaming, Zero copy, Parser Combinators Library in Rust |date=2015 |chapter-url=https://ieeexplore.ieee.org/document/7163218 |pages=142–148 |doi=10.1109/SPW.2015.31 |isbn=978-1-4799-9933-0 |s2cid=16608844 |archive-date=2022-10-09 |access-date=2022-10-09 |archive-url=https://web.archive.org/web/20221009201729/https://ieeexplore.ieee.org/document/7163218 |url-status=live}} Static dispatch is used by default to eliminate method calls, except for methods called on dynamic trait objects.{{sfn|McNamara|2021|p=20}} The compiler also uses inline expansion to eliminate function calls and statically-dispatched method invocations.{{Cite web |title=Code generation |url=https://doc.rust-lang.org/reference/attributes/codegen.html |access-date=2022-10-09 |website=The Rust Reference |archive-date=2022-10-09 |archive-url=https://web.archive.org/web/20221009202615/https://doc.rust-lang.org/reference/attributes/codegen.html |url-status=live}}

    Since Rust uses LLVM, all performance improvements in LLVM apply to Rust also.{{cite web |url=https://doc.rust-lang.org/1.0.0/complement-lang-faq.html#how-fast-is-rust? |title=How Fast Is Rust? |website=The Rust Programming Language FAQ |access-date=11 April 2019 |archive-date=28 October 2020 |archive-url=https://web.archive.org/web/20201028102013/https://doc.rust-lang.org/1.0.0/complement-lang-faq.html#how-fast-is-rust? |url-status=live}} Unlike C and C++, Rust allows for reordering struct and enum elements{{Cite book |url=https://dlnext.acm.org/doi/abs/10.1145/3445814.3446724 |access-date=2022-07-12 |year=2021 |language=en |doi=10.1145/3445814.3446724 |quote=... While some compilers (e.g., Rust) support structure reordering [82], C & C++ compilers are forbidden to reorder data structures (e.g., struct or class) [74] ... |last1=Farshin |first1=Alireza |last2=Barbette |first2=Tom |last3=Roozbeh |first3=Amir |last4=Maguire Jr |first4=Gerald Q. |last5=Kostić |first5=Dejan |title=Proceedings of the 26th ACM International Conference on Architectural Support for Programming Languages and Operating Systems |chapter=PacketMill: Toward per-Core 100-GBPS networking |pages=1–17 |isbn=9781450383172 |s2cid=231949599 |archive-date=2022-07-12 |archive-url=https://web.archive.org/web/20220712060927/https://dlnext.acm.org/doi/abs/10.1145/3445814.3446724 |url-status=live}} to reduce the sizes of structures in memory, for better memory alignment, and to improve cache access efficiency.

    Adoption

    {{See also|Category:Rust (programming language) software}}

    File:Firefox logo, 2019.svg has components written in Rust as part of the underlying Gecko browser engine.]]

    Rust is used in software across different domains. Components from the Servo browser engine (funded by Mozilla and Samsung) were incorporated in the Gecko browser engine underlying Firefox.{{Cite web |last=Keizer |first=Gregg |date=2016-10-31 |title=Mozilla plans to rejuvenate Firefox in 2017 |url=https://www.computerworld.com/article/3137050/mozilla-plans-to-rejuvenate-firefox-in-2017.html |access-date=2023-05-13 |website=Computerworld |language=en |archive-date=2023-05-13 |archive-url=https://web.archive.org/web/20230513020437/https://www.computerworld.com/article/3137050/mozilla-plans-to-rejuvenate-firefox-in-2017.html |url-status=live }} In January 2023, Google (Alphabet) announced support for using third party Rust libraries in Chromium.{{Cite web |last=Claburn |first=Thomas |date=2023-01-12 |title=Google polishes Chromium code with a layer of Rust |url=https://www.theregister.com/2023/01/12/google_chromium_rust/ |access-date=2024-07-17 |website=The Register}}{{Cite web |last=Jansens |first=Dana |date=2023-01-12 |title=Supporting the Use of Rust in the Chromium Project |url=https://security.googleblog.com/2023/01/supporting-use-of-rust-in-chromium.html |access-date=2023-11-12 |website=Google Online Security Blog |language=en |archive-date=2023-01-13 |archive-url=https://web.archive.org/web/20230113004438/https://security.googleblog.com/2023/01/supporting-use-of-rust-in-chromium.html |url-status=live }}

    Rust is used in several backend software projects of large web services. OpenDNS, a DNS resolution service owned by Cisco, uses Rust internally.{{Cite web |last=Shankland |first=Stephen |date=2016-07-12 |title=Firefox will get overhaul in bid to get you interested again |url=https://www.cnet.com/tech/services-and-software/firefox-mozilla-gets-overhaul-in-a-bid-to-get-you-interested-again/ |access-date=2022-07-14 |publisher=CNET |language=en |archive-date=2022-07-14 |archive-url=https://web.archive.org/web/20220714172029/https://www.cnet.com/tech/services-and-software/firefox-mozilla-gets-overhaul-in-a-bid-to-get-you-interested-again/ |url-status=live }}{{Cite web |author=Security Research Team |date=2013-10-04 |title=ZeroMQ: Helping us Block Malicious Domains in Real Time |url=https://umbrella.cisco.com/blog/zeromq-helping-us-block-malicious-domains |access-date=2023-05-13 |website=Cisco Umbrella |language=en-US |archive-date=2023-05-13 |archive-url=https://web.archive.org/web/20230513161542/https://umbrella.cisco.com/blog/zeromq-helping-us-block-malicious-domains |url-status=dead }} Amazon Web Services uses Rust in "performance-sensitive components" of its several services. In 2019, AWS open-sourced Firecracker, a virtualization solution primarily written in Rust.{{Cite web |last=Cimpanu |first=Catalin |title=AWS to sponsor Rust project |url=https://www.zdnet.com/article/aws-to-sponsor-rust-project/ |date=2019-10-15 |access-date=2024-07-17 |website=ZDNET |language=en}} Microsoft Azure IoT Edge, a platform used to run Azure services on IoT devices, has components implemented in Rust.{{Cite web|url=https://www.theregister.co.uk/2018/06/27/microsofts_next_cloud_trick_kicking_things_out_of_the_cloud_to_azure_iot_edge/|title=Microsoft's next trick? Kicking things out of the cloud to Azure IoT Edge|last=Nichols|first=Shaun|date=27 June 2018|website=The Register|language=en|access-date=2019-09-27|archive-date=2019-09-27|archive-url=https://web.archive.org/web/20190927092433/https://www.theregister.co.uk/2018/06/27/microsofts_next_cloud_trick_kicking_things_out_of_the_cloud_to_azure_iot_edge/|url-status=live}} Microsoft also uses Rust to run containerized modules with WebAssembly and Kubernetes.{{Cite web |last=Tung |first=Liam |date=2020-04-30 |title=Microsoft: Why we used programming language Rust over Go for WebAssembly on Kubernetes app |url=https://www.zdnet.com/article/microsoft-why-we-used-programming-language-rust-over-go-for-webassembly-on-kubernetes-app/ |access-date=2022-04-21 |website=ZDNET |language=en |archive-date=April 21, 2022 |archive-url=https://web.archive.org/web/20220421043549/https://www.zdnet.com/article/microsoft-why-we-used-programming-language-rust-over-go-for-webassembly-on-kubernetes-app/ |url-status=live}} Cloudflare, a company providing content delivery network services, used Rust to build a new web proxy named Pingora for increased performance and efficiency.{{Cite web |last=Claburn |first=Thomas |date=20 September 2022 |title=In Rust We Trust: Microsoft Azure CTO shuns C and C++ |url=https://www.theregister.com/2022/09/20/rust_microsoft_c/ |access-date=7 July 2024 |website=The Register}} The npm package manager used Rust for its production authentication service in 2019.{{Cite web |last=Simone |first=Sergio De |date=2019-03-10 |title=NPM Adopted Rust to Remove Performance Bottlenecks |url=https://www.infoq.com/news/2019/03/rust-npm-performance/ |access-date=2023-11-20 |website=InfoQ |language=en |archive-date=2023-11-19 |archive-url=https://web.archive.org/web/20231119135434/https://www.infoq.com/news/2019/03/rust-npm-performance/ |url-status=live }}{{Cite book |last=Lyu |first=Shing |chapter=Welcome to the World of Rust |date=2020 |chapter-url=https://doi.org/10.1007/978-1-4842-5599-5_1 |title=Practical Rust Projects: Building Game, Physical Computing, and Machine Learning Applications |pages=1–8 |editor-last=Lyu |editor-first=Shing |access-date=2023-11-29 |place=Berkeley, CA |publisher=Apress |language=en |doi=10.1007/978-1-4842-5599-5_1 |isbn=978-1-4842-5599-5}}{{Cite book |last=Lyu |first=Shing |chapter=Rust in the Web World |date=2021 |chapter-url=https://doi.org/10.1007/978-1-4842-6589-5_1 |title=Practical Rust Web Projects: Building Cloud and Web-Based Applications |pages=1–7 |editor-last=Lyu |editor-first=Shing |access-date=2023-11-29 |place=Berkeley, CA |publisher=Apress |language=en |doi=10.1007/978-1-4842-6589-5_1 |isbn=978-1-4842-6589-5}}

    File:Rust for Linux logo.svg project has been supported in the Linux kernel since 2022.]]

    In operating systems, the Rust for Linux project, launched in 2020, merged initial support into the Linux kernel version 6.1 in late 2022.{{Cite web |last1=Li |first1=Hongyu |last2=Guo |first2=Liwei |last3=Yang |first3=Yexuan |last4=Wang |first4=Shangguang |last5=Xu |first5=Mengwei |date=2024-06-30 |title=An Empirical Study of Rust-for-Linux: The Success, Dissatisfaction, and Compromise |url=https://www.usenix.org/publications/loginonline/empirical-study-rust-linux-success-dissatisfaction-and-compromise |access-date=2024-11-28 |website=USENIX |language=en}}{{Cite web |last=Corbet |first=Jonathan |date=2022-10-13 |title=A first look at Rust in the 6.1 kernel |url=https://lwn.net/Articles/910762/ |access-date=2023-11-11 |website=LWN.net |archive-date=2023-11-17 |archive-url=https://web.archive.org/web/20231117141103/https://lwn.net/Articles/910762/ |url-status=live }}{{Cite news |last=Vaughan-Nichols |first=Steven |date=7 December 2021 |title=Rust takes a major step forward as Linux's second official language |url=https://www.zdnet.com/article/rust-takes-a-major-step-forward-as-linuxs-second-official-language/ |access-date=2024-11-27 |work=ZDNET |language=en}} The project is active with a team of 6–7 developers, and has added more Rust code with kernel releases from 2022 to 2024,{{Cite web |last=Corbet |first=Jonathan |date=2022-11-17 |title=Rust in the 6.2 kernel |url=https://lwn.net/Articles/914458/ |access-date=2024-11-28 |website=LWN.net}} aiming to demonstrate the minimum viability of the project and resolve key compatibility blockers.{{Cite web |last=Corbet |first=Jonathan |date=2024-09-24 |title=Committing to Rust in the kernel |url=https://lwn.net/Articles/991062/ |access-date=2024-11-28 |website=LWN.net}} The first drivers written in Rust were merged into the kernel for version 6.8. The Android developers used Rust in 2021 to rewrite existing components.{{Cite web |last=Amadeo |first=Ron |date=2021-04-07 |title=Google is now writing low-level Android code in Rust |url=https://arstechnica.com/gadgets/2021/04/google-is-now-writing-low-level-android-code-in-rust/ |access-date=2022-04-21 |website=Ars Technica |language=en-us |archive-date=April 8, 2021 |archive-url=https://web.archive.org/web/20210408001446/https://arstechnica.com/gadgets/2021/04/google-is-now-writing-low-level-android-code-in-rust/ |url-status=live}}{{cite web |author1=Darkcrizt |title=Google Develops New Bluetooth Stack for Android, Written in Rust |url=https://blog.desdelinux.net/en/google-develops-a-new-bluetooth-stack-for-android-written-in-rust/ |website=Desde Linux |date=April 2, 2021 |access-date=31 August 2024 |archive-url=https://web.archive.org/web/20210825165930/https://blog.desdelinux.net/en/google-develops-a-new-bluetooth-stack-for-android-written-in-rust/ |archive-date=25 August 2021}} Microsoft has rewritten parts of Windows in Rust.{{Cite web |last=Claburn |first=Thomas |title=Microsoft is rewriting core Windows libraries in Rust |url=https://www.theregister.com/2023/04/27/microsoft_windows_rust/ |date=2023-04-27 |access-date=2023-05-13 |website=The Register |language=en |archive-date=2023-05-13 |archive-url=https://web.archive.org/web/20230513082735/https://www.theregister.com/2023/04/27/microsoft_windows_rust/ |url-status=live }} The r9 project aims to re-implement Plan 9 from Bell Labs in Rust.{{cite web |last1=Proven |first1=Liam |date=1 December 2023 |title=Small but mighty, 9Front's 'Humanbiologics' is here for the truly curious |url=https://www.theregister.com/2023/12/01/9front_humanbiologics/ |website=The Register |access-date=7 March 2024}} Rust has been used in the development of new operating systems such as Redox, a "Unix-like" operating system and microkernel,{{cite news |last=Yegulalp |first=Serdar |date=21 March 2016 |title=Rust's Redox OS could show Linux a few new tricks |url=http://www.infoworld.com/article/3046100/open-source-tools/rusts-redox-os-could-show-linux-a-few-new-tricks.html |access-date=21 March 2016 |work=InfoWorld |archive-date=21 March 2016 |archive-url=https://web.archive.org/web/20160321192838/http://www.infoworld.com/article/3046100/open-source-tools/rusts-redox-os-could-show-linux-a-few-new-tricks.html |url-status=dead}} Theseus, an experimental operating system with modular state management,{{Cite web |first=Tim |last=Anderson |date=2021-01-14 |title=Another Rust-y OS: Theseus joins Redox in pursuit of safer, more resilient systems |url=https://www.theregister.com/2021/01/14/rust_os_theseus/ |access-date=2022-07-14 |website=The Register |language=en |archive-date=2022-07-14 |archive-url=https://web.archive.org/web/20220714112619/https://www.theregister.com/2021/01/14/rust_os_theseus/ |url-status=live }}{{Cite book |last1=Boos |first1=Kevin |last2=Liyanage |first2=Namitha |last3=Ijaz |first3=Ramla |last4=Zhong |first4=Lin |date=2020 |title=Theseus: an Experiment in Operating System Structure and State Management |url=https://www.usenix.org/conference/osdi20/presentation/boos |language=en |pages=1–19 |isbn=978-1-939133-19-9 |archive-date=2023-05-13 |access-date=2023-05-13 |archive-url=https://web.archive.org/web/20230513164135/https://www.usenix.org/conference/osdi20/presentation/boos |url-status=live }} and most of Fuchsia.{{cite web |first1=HanDong |last1=Zhang |title=2022 Review {{!}} The adoption of Rust in Business |url=https://rustmagazine.org/issue-1/2022-review-the-adoption-of-rust-in-business/ |date=2023-01-31 |website=Rust Magazine |access-date=February 7, 2023 |language=en}} Rust is also used for command-line tools and operating system components, including stratisd, a file system manager{{cite web |url=https://www.marksei.com/fedora-29-new-features-startis/ |title=Fedora 29 new features: Startis now officially in Fedora |last=Sei |first=Mark |date=10 October 2018 |website=Marksei, Weekly sysadmin pills |access-date=2019-05-13 |archive-date=2019-04-13 |archive-url=https://web.archive.org/web/20190413075055/https://www.marksei.com/fedora-29-new-features-startis/ |url-status=live}}{{Cite web |last=Proven |first=Liam |date=2022-07-12 |title=Oracle Linux 9 released, with some interesting additions |url=https://www.theregister.com/2022/07/12/oracle_linux_9/ |access-date=2022-07-14 |website=The Register |language=en |archive-date=2022-07-14 |archive-url=https://web.archive.org/web/20220714073400/https://www.theregister.com/2022/07/12/oracle_linux_9/ |url-status=live }} and COSMIC, a desktop environment by System76.{{Cite web |last=Proven |first=Liam |date=2023-02-02 |title=System76 teases features coming in homegrown Rust-based desktop COSMIC |url=https://www.theregister.com/2023/02/02/system76_cosmic_xfce_updates/ |access-date=2024-07-17 |website=The Register |language=en |archive-date=2024-07-17 |archive-url=https://web.archive.org/web/20240717145511/https://www.theregister.com/2023/02/02/system76_cosmic_xfce_updates/ |url-status=live }}

    In web development, Deno, a secure runtime for JavaScript and TypeScript, is built on top of V8 using Rust and Tokio.{{Cite web |first=Vivian |last=Hu |date=2020-06-12 |title=Deno Is Ready for Production |url=https://www.infoq.com/news/2020/06/deno-1-ready-production/ |access-date=2022-07-14 |website=InfoQ |language=en |archive-date=2020-07-01 |archive-url=https://web.archive.org/web/20200701105007/https://www.infoq.com/news/2020/06/deno-1-ready-production/ |url-status=live }} Other notable adoptions in this space include Ruffle, an open-source SWF emulator,{{Cite web|last=Abrams|first=Lawrence|date=2021-02-06|title=This Flash Player emulator lets you securely play your old games|url=https://www.bleepingcomputer.com/news/software/this-flash-player-emulator-lets-you-securely-play-your-old-games/|access-date=2021-12-25|website=Bleeping Computer|language=en-us|archive-date=2021-12-25 |archive-url=https://web.archive.org/web/20211225124131/https://www.bleepingcomputer.com/news/software/this-flash-player-emulator-lets-you-securely-play-your-old-games/|url-status=live}} and Polkadot, an open source blockchain and cryptocurrency platform.{{Cite web |last=Kharif |first=Olga |date=October 17, 2020 |title=Ethereum Blockchain Killer Goes By Unassuming Name of Polkadot |url=https://www.bloomberg.com/news/articles/2020-10-17/ethereum-blockchain-killer-goes-by-unassuming-name-of-polkadot |url-access=subscription |access-date=July 14, 2021 |website=Bloomberg News |publisher=Bloomberg L.P. |archive-date=2020-10-17 |archive-url=https://web.archive.org/web/20201017192915/https://www.bloomberg.com/news/articles/2020-10-17/ethereum-blockchain-killer-goes-by-unassuming-name-of-polkadot |url-status=live }}

    Discord, an instant messaging software company, rewrote parts of its system in Rust for increased performance in 2020. In the same year, Dropbox announced that its file synchronization had been rewritten in Rust. Facebook (Meta) used Rust to redesign its system that manages source code for internal projects.

    In the 2024 Stack Overflow Developer Survey, 12.6% of respondents had recently done extensive development in Rust.{{Cite web |title=2024 Stack Overflow Developer Survey – Technology |url=https://survey.stackoverflow.co/2024/technology |access-date=2024-11-28 |website=Stack Overflow}} The survey named Rust the "most admired programming language" every year from 2016 to 2024 (inclusive), based on the number of existing developers interested in continuing to work in the same language.{{Cite web |last=Claburn |first=Thomas |date=2022-06-23 |title=Linus Torvalds says Rust is coming to the Linux kernel |url=https://www.theregister.com/2022/06/23/linus_torvalds_rust_linux_kernel/ |access-date=2022-07-15 |website=The Register |language=en |archive-date=2022-07-28 |archive-url=https://web.archive.org/web/20220728221531/https://www.theregister.com/2022/06/23/linus_torvalds_rust_linux_kernel/ |url-status=live }}{{refn|group=note|That is, among respondents who have done "extensive development work [with Rust] in over the past year" (12.6%), Rust had the largest percentage who also expressed interest to "work in [Rust] over the next year" (82.2%).}} In 2024, Rust was the 6th "most wanted technology", with 28.7% of developers not currently working in Rust expressing an interest in doing so.

    In academic research

    Rust has been studied in academic research, both for properties of the language itself as well as the utility the language provides for writing software used for research. Its features around safety{{Cite journal |last1=Jung |first1=Ralf |last2=Jourdan |first2=Jacques-Henri |last3=Krebbers |first3=Robbert |last4=Dreyer |first4=Derek |date=2017-12-27 |title=RustBelt: securing the foundations of the Rust programming language |url=https://dl.acm.org/doi/10.1145/3158154 |journal=Proceedings of the ACM on Programming Languages |language=en |volume=2 |issue=POPL |pages=1–34 |doi=10.1145/3158154 |issn=2475-1421|hdl=21.11116/0000-0003-34C6-3 |hdl-access=free }} and performance{{Cite journal |last1=Popescu |first1=Natalie |last2=Xu |first2=Ziyang |last3=Apostolakis |first3=Sotiris |last4=August |first4=David I. |last5=Levy |first5=Amit |date=2021-10-20 |title=Safer at any speed: automatic context-aware safety enhancement for Rust |journal=Proceedings of the ACM on Programming Languages |language=en |volume=5 |issue=OOPSLA |pages=1–23 |doi=10.1145/3485480 |issn=2475-1421|doi-access=free }} have been examined.

    In a journal article published to Proceedings of the International Astronomical Union, astrophysicists Blanco-Cuaresma and Bolmont re-implemented programs responsible for simulating multi-planet systems in Rust, and found it to be a competitive programming language for its "speed and accuracy". Likewise, an article published on Nature shared several stories of bioinformaticians using Rust for its performance and safety. However, both articles have cited Rust's unique concepts, including its ownership system, being difficult to learn as one of the main drawbacks to adopting Rust.

    Community

    File:Rustacean-orig-noshadow.svg) and have adopted an orange crab, Ferris, as their unofficial mascot.{{sfn|Klabnik|Nichols|2019|p=4}}{{cite web |title=Getting Started |url=https://www.rust-lang.org/learn/get-started#ferris |website=The Rust Programming Language |access-date=11 October 2020 |archive-date=1 November 2020 |archive-url=https://web.archive.org/web/20201101145703/https://www.rust-lang.org/learn/get-started#ferris |url-status=live}}]]

    Rust has been cited as having an inclusive community. According to one MIT Technology Review article, the Rust community was seen as "unusually friendly" to newcomers and particularly attracted people from the queer community, partly due to its code of conduct which outlined a set of expectations for Rust community members to follow. According to the 2024 survey conducted by the Rust survey team and published on the official blog, about 8.3% of Rust developers identify as lesbian, gay, bisexual, queer, or non-heterosexual (54.1% of 15.5%) and 5.5% as transgender (35.8% of 15.5%).{{Cite web |title=2024 State of Rust Survey Results {{!}} Rust Blog |url=https://blog.rust-lang.org/2025/02/13/2024-State-Of-Rust-Survey-results.html |access-date=2025-04-06 |website=blog.rust-lang.org |language=en}} About 22.4% of Rust developers live in the United States, followed by 14.1% in Germany, 6.1% in the United Kingdom, 5.5% in France, and 5.3% in China. As of the 2023 survey, 93% of Rust developers use English for technical communication.{{Cite web |title=2023 Annual Rust Survey Results {{!}} Rust Blog |url=https://blog.rust-lang.org/2024/02/19/2023-Rust-Annual-Survey-2023-results.html |access-date=2025-04-06 |website=blog.rust-lang.org |language=en}}

    = Rust Foundation =

    {{Infobox organization

    | name = Rust Foundation

    | logo = Rust Foundation logo.png

    | formation = {{Start date and age|2021|02|08}}

    | founders = {{unbulleted list|Amazon Web Services|Google|Huawei|Microsoft|Mozilla Foundation}}

    | type = Nonprofit organization

    | location_country = United States

    | leader_title = Chairperson

    | leader_name = Shane Miller

    | leader_title2 = Executive Director

    | leader_name2 = Rebecca Rumbul

    | website = {{URL|https://foundation.rust-lang.org}}

    }}

    The Rust Foundation is a non-profit membership organization incorporated in United States, with the primary purposes of backing the technical project as a legal entity and helping to manage the trademark and infrastructure assets.{{Cite web |first=Liam |last=Tung |date=2021-02-08 |title=The Rust programming language just took a huge step forwards |url=https://www.zdnet.com/article/the-rust-programming-language-just-took-a-huge-step-forwards/ |access-date=2022-07-14 |website=ZDNET |language=en |archive-date=2022-07-14 |archive-url=https://web.archive.org/web/20220714105527/https://www.zdnet.com/article/the-rust-programming-language-just-took-a-huge-step-forwards/ |url-status=live }}{{Cite web |last=Vigliarolo |first=Brandon |date=2021-02-10 |title=The Rust programming language now has its own independent foundation |url=https://www.techrepublic.com/article/the-rust-programming-language-now-has-its-own-independent-foundation/ |archive-url=https://web.archive.org/web/20230320172900/https://www.techrepublic.com/article/the-rust-programming-language-now-has-its-own-independent-foundation/ |archive-date=2023-03-20 |access-date=2022-07-14 |website=TechRepublic |language=en-US}}

    It was established on February 8, 2021, with five founding corporate members (Amazon Web Services, Huawei, Google, Microsoft, and Mozilla).{{cite news|first=Paul|last=Krill|date=9 February 2021|title=Rust language moves to independent foundation|url=https://www.infoworld.com/article/3606774/rust-language-moves-to-independent-foundation.html|work=InfoWorld|access-date=10 April 2021|archive-date=10 April 2021|archive-url=https://web.archive.org/web/20210410161528/https://www.infoworld.com/article/3606774/rust-language-moves-to-independent-foundation.html|url-status=live}} The foundation's board is chaired by Shane Miller.{{cite news|first=Steven J.|last=Vaughan-Nichols|date=9 April 2021|title=AWS's Shane Miller to head the newly created Rust Foundation|url=https://www.zdnet.com/article/awss-shane-miller-to-head-the-newly-created-rust-foundation/|website=ZDNET|access-date=10 April 2021|archive-date=10 April 2021|archive-url=https://web.archive.org/web/20210410031305/https://www.zdnet.com/article/awss-shane-miller-to-head-the-newly-created-rust-foundation/|url-status=live}} Starting in late 2021, its Executive Director and CEO is Rebecca Rumbul.{{Cite news|url=https://www.zdnet.com/article/rust-foundation-appoints-rebecca-rumbul-as-executive-director/|title=Rust Foundation appoints Rebecca Rumbul as executive director|website=ZDNET|first=Steven J.|last=Vaughan-Nichols|date=17 November 2021|access-date=18 November 2021|archive-date=November 18, 2021|archive-url=https://web.archive.org/web/20211118062346/https://www.zdnet.com/article/rust-foundation-appoints-rebecca-rumbul-as-executive-director/|url-status=live}} Prior to this, Ashley Williams was interim executive director.

    = Governance teams =

    The Rust project is composed of teams that are responsible for different subareas of the development. The compiler team develops, manages, and optimizes compiler internals; and the language team designs new language features and helps implement them. The Rust project website lists 6 top-level teams {{as of|July 2024|lc=y}}.{{Cite web |title=Governance |url=https://www.rust-lang.org/governance |access-date=2024-07-18 |website=The Rust Programming Language |language=en-US |archive-date=May 10, 2022 |archive-url=https://web.archive.org/web/20220510225505/https://www.rust-lang.org/governance |url-status=live}} Representatives among teams form the Leadership council, which oversees the Rust project as a whole.{{Cite web |title=Introducing the Rust Leadership Council |url=https://blog.rust-lang.org/2023/06/20/introducing-leadership-council.html |access-date=2024-01-12 |website=Rust Blog |language=en}}

    See also

    Notes

    {{Reflist|group=note}}

    References

    = Book sources =

    {{refbegin}}

    • {{Cite book |last=Gjengset |first=Jon |url=https://www.worldcat.org/oclc/1277511986 |title=Rust for Rustaceans |date=2021 |publisher=No Starch Press |isbn=9781718501850 |edition=1st |oclc=1277511986 |language=en}}
    • {{Cite book|last1=Klabnik|first1=Steve|url=https://books.google.com/books?id=0Vv6DwAAQBAJ|title=The Rust Programming Language (Covers Rust 2018)|last2=Nichols|first2=Carol|date=2019-08-12|publisher=No Starch Press|isbn=978-1-7185-0044-0|language=en}}
    • {{Cite book|last1=Blandy|first1=Jim|last2=Orendorff|first2=Jason|last3=Tindall|first3=Leonora F. S.|url=https://www.worldcat.org/oclc/1289839504|date=2021|edition=2nd|title=Programming Rust: Fast, Safe Systems Development|publisher=O'Reilly Media|isbn=978-1-4920-5254-8 |language=en|oclc=1289839504}}
    • {{Cite book|last1=McNamara|first1=Tim|url=https://www.worldcat.org/oclc/1153044639|title=Rust in Action|oclc=1153044639|date=2021|publisher=Manning Publications|isbn=978-1-6172-9455-6|language=en}}
    • {{Cite book |last1=Klabnik |first1=Steve |last2=Nichols |first2=Carol |url=https://www.worldcat.org/oclc/1363816350 |title=The Rust programming language |date=2023 |publisher=No Starch Press |isbn=978-1-7185-0310-6 |edition=2nd |oclc=1363816350}}

    {{refend}}

    = Others =

    {{reflist|refs=

    {{cite web |url=https://www.rust-lang.org/policies/licenses |title=Licenses |access-date=2025-03-07 |website=The Rust Programming Language |archive-date=2025-02-23 |archive-url=https://web.archive.org/web/20250223193908/https://www.rust-lang.org/policies/licenses |url-status=live}}

    {{cite web |title=Influences |url=https://doc.rust-lang.org/reference/influences.html |website=The Rust Reference |access-date=December 31, 2023 |archive-date=November 26, 2023 |archive-url=https://web.archive.org/web/20231126231034/https://doc.rust-lang.org/reference/influences.html |url-status=live}}

    {{Cite arXiv|last=Jaloyan |first=Georges-Axel |date=19 October 2017 |title=Safe Pointers in SPARK 2014 |class=cs.PL |eprint=1710.07047}}

    {{cite web |url=http://nondot.org/sabre/ |title=Chris Lattner's Homepage |last=Lattner |first=Chris |date= |website=Nondot |access-date=2019-05-14 |archive-date=2018-12-25 |archive-url=https://web.archive.org/web/20181225175312/http://nondot.org/sabre/ |url-status=live}}

    {{cite web|url=https://www.zdnet.com/article/microsoft-opens-up-rust-inspired-project-verona-programming-language-on-github/|title=Microsoft opens up Rust-inspired Project Verona programming language on GitHub|website=ZDNET|access-date=2020-01-17|archive-date=2020-01-17|archive-url=https://web.archive.org/web/20200117143852/https://www.zdnet.com/article/microsoft-opens-up-rust-inspired-project-verona-programming-language-on-github/|url-status=live}}

    }}