Rust (programming language): Difference between revisions - Wikipedia


Article Images

Content deleted Content added

Chardon55

(talk | contribs)

102 edits

(10 intermediate revisions by 8 users not shown)

Line 15:

}}

| released = {{Start date and age|2015|05|15}}

| developerdesigner = RustGraydon ProjectHoare

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

Line 59 ⟶ 60:

}}

'''Rust''' is a [[General-purpose programming language|general-purpose]] [[programming language]] emphasizing [[Computer performance|performance]], [[type safety]], and [[Concurrency (computer science)|concurrency]]. It enforces [[memory safety]], meaning that all [[Reference (computer science)|references]] point to valid memory,. It does so without a traditional [[Garbage collection (computer science)|garbage collector]].; To simultaneouslyinstead, enforceboth memory safety anderrors preventand [[data race]]s, itsare prevented by the "borrow checker", which tracks the [[object lifetime]] of all references in a program during [[Compiler|compilingat compile time]].

Rust does not enforce a [[programming paradigm]], but was influenced by ideas from [[functional programming]], including [[Immutable object|immutability]], [[higher-order function]]s, and [[algebraic data type]]s, and [[pattern matching]]. It also supports [[object-oriented programming]] via structs, [[Enumerated type|enums]], traits, and methods. It is popular for [[systems programming]].<ref>{{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}}</ref><ref>{{Cite book |last1=Blandy |first1=Jim |date=2017-11-21 |url=https://books.google.com/books?id=h8c_DwAAQBAJ |title=Programming Rust: Fast, Safe Systems Development |last2=Orendorff |first2=Jason |publisher=O'Reilly Media, Inc. |isbn=978-1-4919-2725-0 |language=en}}</ref><ref name="Astrophysics">{{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}}</ref> Rust does not enforce a [[programming paradigm]], but supports [[object-oriented programming]] via structs, enums, traits, and methods, and supports functional programming via immutability, pure functions, higher order functions, and pattern matching.

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 (company)|Amazon]], [[Discord]], [[Dropbox]], [[Google]] ([[Alphabet Inc.|Alphabet]]), [[Meta Platforms|Meta]], and [[Microsoft]]. In December 2022, it became the first language other than [[C (programming language)|C]] and [[Assembly language|assembly]] to be supported in the development of the [[Linux kernel]].

Line 184 ⟶ 185:

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

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

For expressions work over any [[iterator]] type.

Line 560 ⟶ 561:

</syntaxhighlight>

The borrow checker in the Rust compiler uses lifetimes to ensure that the values a reference points to remain valid.{{sfn|Klabnik|Nichols|2019|pp=75,134}}<ref>{{Cite web |last=Shamrell-Harrington |first=Nell |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}}</ref> In the example above, storing a reference to variable {{code|x}} toin {{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:

<syntaxhighlight lang="rust">

Line 801 ⟶ 802:

In operating systems, the [[Android (operating system)|Android]] developers were using Rust in 2021 to rewrite existing components.<ref>{{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}}</ref><ref>{{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 |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}}</ref>

The [[Rust for Linux]] project, launched in 2020, added initial Rust support to Linux in late 2022, and the first Linux drivers written in Rust were released in late 2023.<ref>{{Cite web |first=Tim |last=Anderson |date=2021-12-07 |title=Rusty Linux kernel draws closer with new patch |url=https://www.theregister.com/2021/12/07/rusty_linux_kernel_draws_closer/ |access-date=2022-07-14 |website=The Register |language=en}}</ref><ref>{{Cite web |title=A first look at Rust in the 6.1 kernel [LWN.net] |url=https://lwn.net/Articles/910762/ |access-date=2023-11-11 |website=lwn.net}}</ref> and [[Android (operating system)|Android]].<ref name=":1">{{Cite web |title=Rust in the Android platform |url=https://security.googleblog.com/2021/04/rust-in-android-platform.html |access-date=2022-04-21 |website=Google Online Security Blog |language=en |archive-date=April 3, 2022 |archive-url=https://web.archive.org/web/20220403015852/https://security.googleblog.com/2021/04/rust-in-android-platform.html |url-status=live}}</ref><ref name="asix">{{cite web |last1=Larabel |first1=Michael |title=The First Rust-Written Network PHY Driver Set To Land In Linux 6.8 |url=https://www.phoronix.com/news/Linux-6.8-Rust-PHY-Driver |website=[[phoronix.com]] |access-date=31 August 2024}}</ref>

[[Microsoft]] is rewriting parts of [[Windows]] in Rust.<ref>{{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}}</ref> The r9 project aims to re-implement [[Plan 9 from Bell Labs]] in Rust.<ref>{{cite web |last1=Proven |first1=Liam |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}}</ref> Rust has been used in the development of new operating systems such as [[Redox (operating system)|Redox]], a "Unix-like" operating system and [[microkernel]],<ref>{{cite news |last=Yegulalp |first=Serdar |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=live}}</ref> Theseus, an experimental operating system with modular state management,<ref>{{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}}</ref><ref>{{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}}</ref> and most of [[Fuchsia (operating system)|Fuchsia]].<ref name="rustmag-1">{{cite web |first1=HanDong (Alex)|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}}</ref> Rust is also used for command-line tools and operating system components, including [[Stratis (configuration daemon)|stratisd]], a [[file system]] manager<ref>{{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}}</ref><ref>{{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}}</ref> and COSMIC, a [[desktop environment]] by [[System76]].<ref>{{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}}</ref>