Everipedia Logo
Everipedia is now IQ.wiki - Join the IQ Brainlist and our Discord for early access to editing on the new platform and to participate in the beta testing.
Rust (programming language)

Rust (programming language)

Rust is a multi-paradigm system programming language[14] focused on safety, especially safe concurrency.[15][16] Rust is syntactically similar to C++,[17] but is designed to provide better memory safety while maintaining high performance.

Rust was originally designed by Graydon Hoare at Mozilla Research, with contributions from Dave Herman, Brendan Eich, and others.[18][19] The designers refined the language while writing the Servo layout or browser engine[20] and the Rust compiler. The compiler is free and open-source software dual-licensed under the MIT License and Apache License 2.0.

Rust was the "most loved programming language" in the Stack Overflow Developer Survey every year since 2016.[21][22][23][24]

Rust
ParadigmsMulti-paradigm:concurrent,functional,generic,imperative,structured
Designed byGraydon Hoare
DeveloperThe Rust Project
First appearedJuly 7, 2010
Stable release
Typing disciplineInferred,linear,nominal,static,strong
Implementation languageRust
PlatformARM,IA-32,x86-64,MIPS,PowerPC,SPARC,RISC-V[2][3]
OSLinux,macOS,Windows,FreeBSD,OpenBSD,[4]Redox,Android,iOS[5]
LicenseMITorApache 2.0[6]
Filename extensions.rs,.rlib
Website
Influenced by
Alef,[7]C#,[7]C++,[7]Cyclone,[7][8]Erlang,[7]Haskell,[7]Limbo,[7]Newsqueak,[7]OCaml,[7]Scheme,[7]Standard ML,[7]Swift[7][9]
Influenced
Crystal,Elm,[10]Idris,[11]Spark,[12]Swift[13]

Design

A presentation on Rust by Emily Dunham from Mozilla's Rust team (linux.conf.au conference, Hobart, 2017).

A presentation on Rust by Emily Dunham from Mozilla's Rust team (linux.conf.au conference, Hobart, 2017).

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

Performance of idiomatic Rust

Performance of idiomatic Rust is comparable to the performance of idiomatic C++.[27][28]

Syntax

The concrete syntax of Rust is similar to C and C++, with blocks of code delimited by curly brackets, and control flow keywords such as if, else, while, and for. Not all C or C++ keywords are implemented, however, and some Rust functions (such as the use of the keyword match for pattern matching) will be less familiar to those versed in these languages. Despite the superficial resemblance to C and C++, the syntax of Rust in a deeper sense is closer to that of the ML family of languages and the Haskell language. Nearly every part of a function body is an expression,[29] even control flow operators. For example, the ordinary if expression also takes the place of C's ternary conditional. A function need not end with a return expression: in this case if the semicolon is omitted the last expression in the function creates the return value.

Memory safety

The system is designed to be memory safe, and it does not permit null pointers, dangling pointers, or data races in safe code.[30][31][32][33] Data values can only be initialized through a fixed set of forms, all of which require their inputs to be already initialized.[34] To replicate the function in other languages of pointers being either valid or NULL, such as in linked list or binary tree data structures, the Rust core library provides an option type, which can be used to test if a pointer has Some value or None.[31] Rust also introduces added syntax to manage lifetimes, and the compiler reasons about these through its borrow checker.

Memory management

Rust does not use an automated garbage collection system like those used by Go, Java, or the .NET Framework. Instead, memory and other resources are managed through the resource acquisition is initialization (RAII) convention, with optional reference counting. Rust provides deterministic management of resources, with very low overhead. Rust also favors stack allocation of values and does not perform implicit boxing.

There is also a concept of references (using the & symbol), which do not involve run-time reference counting.

The safety of using such pointers is verified at compile time by the borrow checker, preventing dangling pointers and other forms of undefined behavior.

Ownership

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

Types and polymorphism

The type system supports a mechanism similar to type classes, called "traits", inspired directly by the Haskell language. This is a facility for ad hoc polymorphism, achieved by adding constraints to type variable declarations. Other features from Haskell, such as higher-kinded polymorphism, are not yet supported.

Rust features type inference, for variables declared with the keyword let. Such variables do not require a value to be initially assigned to determine their type. A compile-time error results if any branch of code fails to assign a value to the variable.[37] Variables assigned multiple times must be marked with the keyword mut.

Functions can be given generic parameters, which usually require the generic type to implement a certain trait or traits. Within such a function, the generic value can only be used through those traits. This means that a generic function can be type-checked as soon as it is defined. This is in contrast to C++ templates, which are fundamentally duck typed and cannot be checked until instantiated with concrete types. C++ concepts address the same issue and are expected to be part of C++20 (2020).

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

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

History

The language grew out of a personal project begun in 2006 by Mozilla employee Graydon Hoare,[16] who stated that the project was possibly named after the rust family of fungi.[38] Mozilla began sponsoring the project in 2009[16] and announced it in 2010.[39][40] The same year, work shifted from the initial compiler (written in OCaml) to the self-hosting compiler written in Rust.[41] Named rustc, it successfully compiled itself in 2011.[42] rustc uses LLVM as its back end.

The first numbered pre-alpha release of the Rust compiler occurred in January 2012.[43] Rust 1.0, the first stable release, was released on May 15, 2015.[44][45] Following 1.0, stable point releases are delivered every six weeks, while features are developed in nightly Rust and then tested with alpha and beta releases that last six weeks.[46]

Along with conventional static typing, before version 0.4, Rust also supported typestates. The typestate system modeled assertions before and after program statements, through use of a special check statement. Discrepancies could be discovered at compile time, rather than when a program was running, as might be the case with assertions in C or C++ code. The typestate concept was not unique to Rust, as it was first introduced in the language NIL.[47] Typestates were removed because in practice they were little used, though the same function can still be achieved with a branding pattern.[48]

The style of the object system changed considerably within versions 0.2, 0.3 and 0.4 of Rust.

Version 0.2 introduced classes for the first time, with version 0.3 adding several features including destructors and polymorphism through the use of interfaces.

In Rust 0.4, traits were added as a means to provide inheritance; interfaces were unified with traits and removed as a separate feature.

Classes were also removed, replaced by a combination of implementations and structured types.

Starting in Rust 0.9 and ending in Rust 0.11, Rust had two built-in pointer types, ~ and @, simplifying the core memory model.

It reimplemented those pointer types in the standard library as Box and (the now removed) Gc.

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

Rust was the third-most-loved programming language in the 2015 Stack Overflow annual survey,[50] and took first place in 2016, 2017, 2018, and 2019.[21][22][53][24]

The language is referenced in The Book of Mozilla as "oxidised metal".[55]

Projects

Web browser

A Web browser and several related components are being written in Rust, including:

  • Firefox[56] Servo – Mozilla's parallel web-browser engine[57] developed in collaboration with Samsung[58] Quantum – a project, composed of several sub-projects, to improve the Gecko web-browser engine of Firefox, developed by Mozilla[59]

Operating systems

Many operating systems (OS) and related components are being written in Rust. As of January 2019, the OSes included: BlogOS, intermezzOS, QuiltOS, Redox, RustOS, Rux, Tefflin, and Tock.[60] Wikipedia articles exist on:

  • Magic Pocket – Dropbox's file system that powers their Diskotech petabyte storage machines[61]

  • Redox – a microkernel[62]

  • Stratis – a file system for Fedora[63] and RHEL 8[64]

  • Railcar – a container runtime by Oracle[65]

  • Firecracker – secure and fast microVMs for serverless computing[66]

Other

  • exa – a "modern replacement for ls"

  • Microsoft Azure IoT Edge – a platform used to run Azure services and artificial intelligence on IoT devices has components implemented in Rust[67]

  • OpenDNS – used in two of its components[68][69][70]

  • Tor – an anonymity network, written in C originally, is experimenting with porting to Rust for its security features.[71][72]

  • TiKV - a distributed key-value database first developed by PingCAP, now a Cloud Native Computing Foundation member project.[73]

  • Wargroove – a video game developed by Chucklefish that uses Rust for its server software[74]

  • Xi – a text editor from Raph Levien,[75] used within the Fuchsia operating system.[76]

  • Deno [81] – A secure runtime for JavaScript and TypeScript built with V8, Rust, and Tokio

  • [1] [82] - Safety, Performance and Innovation: Rust in Hyperledger Sawtooth

Conferences

  • RustConf — An annual conference in Portland, Oregon. Held since 2016.[77]

  • Rust Belt Rust – A #rustlang conference in the Rust Belt[78] 2018: Ann Arbor, Michigan 2017: Columbus, Ohio 2016: Pittsburgh, Pennsylvania

  • RustFest – Europe's @rustlang conference[79] 2018: Rome, Italy 2018: Paris, France 2017: Zürich, Switzerland 2017: Kiev (Київ), Ukraine 2016: Berlin, Germany

  • RustCon Asia 2019: Beijing, China[80]

  • Rust LATAM 2019: Montevideo, Uruguay

See also

  • Comparison of programming languages

References

[1]
Citation Linkblog.rust-lang.orgThe Rust Release Team (26 September 2019). "Announcing Rust 1.38.0". The Rust Programming Language Blog. Retrieved 26 September 2019.
Sep 26, 2019, 11:08 PM
[2]
Citation Linkforge.rust-lang.org"Rust Platform Support". Rust Forge. Retrieved 2019-05-19.
Sep 26, 2019, 11:08 PM
[3]
Citation Linkdocs.rust-embedded.org"Frequently Asked Questions". Rust Embedded. Retrieved 2019-05-14.
Sep 26, 2019, 11:08 PM
[4]
Citation Linkcvsweb.openbsd.org"OpenBSD ports". Retrieved 2018-04-03.
Sep 26, 2019, 11:08 PM
[5]
Citation Linkmozilla.github.io"Building and Deploying a Rust library on iOS". 6 September 2017. Retrieved 11 January 2019.
Sep 26, 2019, 11:08 PM
[6]
Citation Linkwww.rust-lang.org"Rust Legal Policies". Rust-lang.org. Retrieved 2018-04-03.
Sep 26, 2019, 11:08 PM
[7]
Citation Linkdoc.rust-lang.org"The Rust Reference: Appendix: Influences". Retrieved November 11, 2018. Rust is not a particularly original language, with design elements coming from a wide range of sources. Some of these are listed below (including elements that have since been removed): SML, OCaml [...] C++ [...] ML Kit, Cyclone [...] Haskell [...] Newsqueak, Alef, Limbo [...] Erlang [...] Swift [...] Scheme [...] C# [...]
Sep 26, 2019, 11:08 PM
[8]
Citation Linkgithub.com"Note Research: Type System". 2015-02-01. Retrieved 2015-03-25. Papers that have had more or less influence on Rust, or which one might want to consult for inspiration or to understand Rust's background. [...] Region based memory management in Cyclone [...] Safe memory management in Cyclone
Sep 26, 2019, 11:08 PM
[9]
Citation Linkgithub.com"RFC for 'if let' expression". Retrieved December 4, 2014.
Sep 26, 2019, 11:08 PM
[10]
Citation Linkgroups.google.com"Command Optimizations?". 2014-06-26. Retrieved 2014-12-10. I just added the outline of a Result library that lets you use richer error messages. It's like Either except the names are more helpful. The names are inspired by Rust's Result library.
Sep 26, 2019, 11:08 PM
[11]
Citation Linkdocs.idris-lang.org"Idris – Uniqueness Types". Retrieved 2018-11-20.
Sep 26, 2019, 11:08 PM
[12]
Citation Linkarxiv.orgJaloyan, Georges-Axel (19 October 2017). "Safe Pointers in SPARK 2014". Retrieved 1 January 2019. Cite journal requires |journal= (help)
Sep 26, 2019, 11:08 PM
[13]
Citation Linknondot.orgLattner, Chris. "Chris Lattner's Homepage". Nondot.org. Retrieved 2019-05-14.
Sep 26, 2019, 11:08 PM
[14]
Citation Linkwww.rust-lang.org"Rust is a systems programming language". Rust-lang.org. Retrieved 2017-07-17.
Sep 26, 2019, 11:08 PM
[15]
Citation Linkgraydon2.dreamwidth.orgHoare, Graydon (2016-12-28). "Rust is mostly safety". Graydon2. Dreamwidth Studios. Retrieved 2019-05-13.
Sep 26, 2019, 11:08 PM
[16]
Citation Linkweb.archive.org"FAQ – The Rust Project". Rust-lang.org. Retrieved 27 June 2019.
Sep 26, 2019, 11:08 PM
[17]
Citation Linkwww.apriorit.com"Rust vs. C++ Comparison". Retrieved 20 November 2018. Rust is syntactically similar to C++, but it provides increased speed and better memory safety
Sep 26, 2019, 11:08 PM
[18]
Citation Linklambda-the-ultimate.orgNoel (2010-07-08). "The Rust Language". Lambda the Ultimate. Retrieved 2010-10-30.
Sep 26, 2019, 11:08 PM
[19]
Citation Linkgithub.com"Contributors to rust-lang/rust". GitHub. Retrieved 2018-10-12.
Sep 26, 2019, 11:08 PM
[20]
Citation Linkarstechnica.comBright, Peter (2013-04-03). "Samsung teams up with Mozilla to build browser engine for multicore machines". Ars Technica. Retrieved 2013-04-04.
Sep 26, 2019, 11:08 PM