Rust is a system programming language whose creators
paid attention to
three things : concurrency, speed, and security. And although Rust
is considered a young programming language - its first stable version was released in 2015 - it has been developed for more than ten years.
Today we would like to look into the past and tell the story of the Rust language, show how its functions and capabilities have changed during development and provide specific examples of the implementation of this PL in practice.
/ image of Jeff Vier CC')
Personal project (2006–2010)
Technology from the past that is designed to save the future from itself
- Graydon Hoare, developer of Rust
This is one of the quotes of Graidon Choir, which was voiced by Steve Klabnik from the Rust project team during his presentation at the ACM conference in 2016 (you can find the slides to the presentation
by reference , but to move between slides, use arrows on the keyboard). These words well reflect the fact that Rust is
not a revolutionary language with advanced functions. It simply includes many working methods from “old” languages ​​(including C ++), increasing their security.
Greydon Khor
began developing Rust in 2006 - at that time he was a Mozilla employee and was engaged in the project in his free time. According
to Greydon, the language was named after the mushrooms of the
Rust family, because they are “distributed organisms” that do not have a “single point of failure” and have exceptional vitality. Such fungi have five stages of the life cycle and quickly germinate. The chorus decided that this is a good analogy for the PL, which focuses on security and speed.
Pursuing the language, Greydon established certain rules. He
noted that first of all it is necessary to pay attention to the semantics of the language, and work on the syntax is the last thing. Therefore, in the early implementation of Rust, the keywords were no longer than five characters — the language was “short” and used operators such as log, ret, and fn.
For example, the first code on Rust, which saw the light,
looked like this:
fn main() { log "hello, world"; } fn max(int x, int y) -> int { if (x > y) { ret x; } else { ret y; } }
As Steve Klabnik notes, over time, this restriction was lifted: some of the keywords were “extended”, for example, ret turned into return, and some were replaced completely. For comparison, in the modern implementation of the language, the output of the string “Hello world!”
Looks like this:
fn main() { println!("Hello, world!"); }
Also during the evolution of the concepts and keywords of the language has been removed. When Greydon worked on the language, Rust was object-oriented and
used the obj operator to describe objects. Now, as such, OOP is not supported by the language, but Rust makes it possible to implement many of its concepts using abstractions.
Rust also worked with
parametric polymorphism functions. The concepts of generalized programming in the language have been preserved even now (you can find the design of the code in this
document ), but ten years ago, square brackets were used to indicate the type of parameters:
obj swap[T](tup(T,T) pair) -> tup(T,T) { ret tup(pair._1, pair._0); } fn main() { auto str_pair = tup("hi", "there"); auto int_pair = tup(10, 12); str_pair = swap[str](str_pair); int_pair = swap[int](int_pair); }
He himself worked on Rust for four years. During this time, he managed to implement about 90% of the conceived functions (some of which had a rather crude implementation). The environment for code execution was 70% complete. In total during this time, Khor wrote 38 thousand lines of code for the
OCaml compiler.
Transition to Mozilla (2010–2012)
I do not think that the language should have some main features.
It should consist of a set of clear and reliable modules that work well in combination with each other.
- Graydon Hoare, developer of Rust
After four years, Greydon
decided to show his prototype to the manager in Mozilla. The company showed interest in the project, because they were looking for a tool to rebuild the browser stack on simpler technologies than C ++. Therefore, the company created a team (led by Greydon) to work on Rust, which became the basis of
the Servo browser engine .
Then the Mozilla engine
could not fully work with multi-core systems, since it had single-stream content processing schemes. For example, the functions of forming the window contents and launching JavaScript were single-threaded. Rust made it possible to divide the rendering code into mini-tasks performed in parallel and saving CPU resources.
In addition to speeding up work due to parallelization of operations, Rust allowed to increase the security of the browser. At that time, Firefox was implemented in C ++ and contained 4.5 million lines of code. C ++ is an “accurate” programming language that requires increased attention to detail, so programmer errors could lead to serious vulnerabilities. The task of Rust was to reduce the influence of the human factor with the help of the compiler.
In 2010, the language developers changed the OCaml compiler used before to a compiler written in Rust. In 2011, Greydon published a
message that the compiler was able to successfully “assemble” himself, and in 2012 the Rust team
announced the release of the alpha version of the compiler - its documentation was not complete, and the build speed was far from ideal, but supported most language functions and cross-compilation.
Years typesystem (2012–2014)
Our target audience is “frustrated C ++ developers”
- Graydon Hoare, developer of Rust
At this point, Greydon moved away from work on Rust and switched to other projects. As Steve Klabnik says, after that the control system became more “distributed”. A federal structure was formed in which a separate group of developers was responsible for the changes made in different parts of the project.
The team continued to grow, and people began to appear in it, versed in complex type systems. Therefore, the active development of the typesystem began, and more and more aspects of the language were put into libraries.
For example, in the early stages of Rust, a Garbage Collector (GC) was implemented, which Greydon introduced to increase memory security. But then the developers came to the conclusion that they can provide the same level of reliability with the help of the type system, and GC refused.
This decision also affected the pointer system used in Rust. Before the removal of the garbage collector, there were three main indicators in the language:
After the removal of the GC, the pointer system changed and assumed the following form:
- Box (unique pointer)
- & (borrowed pointer called “link”)
At this stage of the development of a programming language, many improvements were made that are not related to the typesystem. For example, work was carried out on the package manager Cargo and the online repository Crates.io. The developers added the ability to customize the compiler settings, which simplified the transition to Rust from other languages. “Newbies” didn’t have to figure out what a particular flag was needed for when compiling. By the way, you can also find commands for the Cargo Package Manager in the
presentation of Steve Klabnik.
The period from 2012 to 2014 is the time when the Rust community began to take shape. It formed three large "camps": C ++ users, users of scripting languages ​​and functional programmers. Their expertise influenced the language - gradually he began to
combine the paradigms of functional and procedural programming.
In March 2014, an
RFC process was also formed, which was
used to represent significant changes in the language. The solution was built in the image and likeness of Python PEP, and now it has made 3 thousand commits. And in the RFC gets any change, even made by developers. According to the rules of the Rust team, no one can make major changes without discussing the decision with the community.
Release (2015)
We do not know for sure what will come of it.
- Graydon Hoare, developer of Rust
In early 2015, Rust 1.0 Alpha was
released . It stabilized the core of the language, developed a system of macros, and, finally, assigned the
names isize and usize to the integer types int and uint. At the beginning of the second quarter of the same year, Rust 1.0
went into beta - by this time crates.io had 1,700 craites (
the compilation unit ), and the number of downloads from the repository exceeded one million.
In May 2015, the official release took place -
Rust 1.0 . This marked the beginning of stability. From this point on, all the changes introduced
were backward compatible, which allowed Rust to be used in real projects. He began to find applications in areas such as game dev, web development and development of operating systems.
Transition to production (May 2016)
If the language is good only in one thing, then this is a failure.
- Graydon Hoare, developer of Rust
In 2015, the StackOverflow platform conducted a survey among developers in which they were asked to note which programming languages ​​they worked with and which they would like to meet. Then Rust
took the third line of the rating. However, a year later, he
moved to the first place - 79% of users expressed a desire to continue working with him.
One of the residents of Hacker News
called the main advantages of the language transparency and ease of documentation. Other users also noted the openness and goodwill of the Rust community, which is always ready to help with the study of the features of PL.
However, many developers decide to continue working with this language due to its security mechanisms. As one of the users of Reddit said: “Programming on Rust is like a parkour with insurance and protection; sometimes it looks weird, but you can do many tricks without fear of breaking something for yourself. ”
Since the release of the stable version of Rust, the period of its full use in production has begun. One of the first companies that applied Rust to their project
was Mozilla. Some of the "insides" of Firefox 45 for Linux were rewritten to Rust, and since Firefox 47, the Rust code is also present in the Windows version. Their
Project Quantum , announced in October 2016, also incorporates Servo components.
Rust
is also
used in Dropbox - the core of their product is written on this PL. The company Dropbox has
created its new cloud storage Magic Pocket, into which it
transferred information from Amazon S3. Initially, it was implemented in the Go language, but under heavy loads, the problem was high memory consumption and low predictability of code behavior on Go. To solve these problems was partially involved Rust.
Last year, we started using Rust to process JavaScript packages in npm. Rust helped eliminate delays in a system that works with 350 million packages per day. Ashley Williams (Ashley Williams), npm support service specialist,
spoke about the experience of using Rust at the RustFest conference in Ukraine. You can find the video
here .
Rust also uses us at Bitfury. In this programming language, our framework for creating
Exonum blockchains is
implemented . For the first time, we presented the platform at the RustFest 2017 conference, where we showed its capabilities and conducted a workshop where we demonstrated the work of the cryptocurrency service (a brief guide on how to create cryptocurrency on Exonum can be found
here ).
The implementation on Rust
was the way to work with smart contracts. Because of this, Exonum smart contracts have better performance than Ethereum (or Fabric) contracts. The platform code is completely open and lies in the project repository on
GitHub .
Rust also finds application in the field of information security. Projects like Tor already
transfer part of the code to Rust.
In general, today 105 companies use Rust in their products. Their complete list (in which the Bitfury Group is also noted) can be found on the
Friends of Rust page on the official website. And the number of companies creating software products on Rust is constantly increasing, which the language developers are
very pleased about .
- February 28 in Moscow, we will hold a Rust-MAP with the developers of Exonum, Bitfury Group and Parity Technologies. We will discuss the creation of smart contracts using Rust & WebAssembly. In addition to the report, there will be a practical part on the creation of WASM contracts for Exonum. More about the event here .
- On March 1, we will hold an open workshop where we will show how not only smart contacts can be transferred to WASM, but also the client part of the Exonum-blockchain. Details of the meeting can be found on the link .
Entrance to the event is free by prior registration.