The new kid on the block

Rust continues to top the charts of the most admired and desired languages for developers. In this article we will try to understand why the “new kid on the block” language Rust is attracting increasing interest in systems programming circles and beyond.

But first a timeline to understand how the language was born and how it has evolved:

2006
Graydon Hoare begins work on a new programming language called Rust, from “plant rust,” a fungus parasitic on vegetation
June 16, 2010First public git commit of Rust; Rust becomes a Mozilla project.
2015Version 1.0 of Rust is released and the project becomes independent of Mozilla, although the latter remains the project’s main funder.
11 Agosto 2020Mozilla announces a restructuring and layoff of about 250 people, including many of the Rust team, in part due to the economic effects of the COVID-19 pandemic.
8 Febbraio 2021The Rust Foundation is launched with support from Amazon Web Services (AWS), Huawei, Google, Microsoft, and Mozilla to evolve the Rust language and its ecosystem.
29 Aprile 2021Facebook joins the Rust Foundation.

Rust, nice to meet you!

Rust is a static and strongly typed programming language that enables the writing of performant and reliable software. In fact, the language sets as its main goal the writing of code that is fast and free from possible memory allocation problems. Problems that, on the other hand, often occur when using a traditional language, as the programmer has to manage memory deallocation manually. The big difference from other languages is that Rust is secure by default; all memory accesses are controlled.

The language is designed to make it more difficult to write programs plagued by memory bugs, and the type system implemented is the greatest evidence of this, as we shall see below when we go into detail about the mechanisms for “borrowing” variables. Rust is a ‘static’ language. All types are known at compile time.

Rust’s elective use is therefore as a “system” programming language, that is, a language that allows low-level software to be written. For example, parts of the operating system or applications and drivers that interact directly with hardware and require measurable execution times. In this category of languages the newcomer stands as a contender for C and C++.
Nevertheless, Rust allows even high-level programming, thanks to its unique memory management features and strong typing, succeeding in this to combine the needs of both worlds: ergonomics and control.

The elective use of Rust is thus that of a “system” programming language

Language features

Let us therefore briefly look at the salient features of this language. We will return to each of them later to elaborate on their significance.

  • Memory Safety: Strict mechanism for enforcing safety in borrowing data in memory.
  • Performance: Rust is designed to be efficient and fast. The language is optimized for low-level programming and is compiled into native code.
  • Data manipulation: Functions, methods and closures to operate on tuples, structures and enums to aggregate data, pattern matching to select and deconstruct data.
  • Traits: defining the behavior of data types using traits.
  • Cross-platform: allows code to be compiled for different platforms, including Windows, Linux, and macOS.
  • Concurrency: Rust, through the concepts of data ownership and borrowing ensures that any concurrent executions accessing the same data do not generate error conditions. The language provides first-rate support for concurrent programming.
  • Error Handling: Strong focus on explicit error handling
  • Syntax: Modern, expressive syntax
  • Ecosystem: Growing ecosystem and package manager (Cargo)
  • Interoperability: Good interoperability with C code

Some clarifications on what Rust is not instead :

  • Not Object Oriented: Rust does not have constructs to create objects, in the proper sense of the term, although through traits one can structure the code so that data types have their own “methods.”
  • Not easy: Rust’s learning curve is certainly steeper than other languages (Java, C#, Python), but comparable with that of languages in the same range (C and C++).

Rust is designed to be secure, efficient, and fast. The language provides first-rate support for concurrent programming.

Installation

To start getting “hands-on” we need to install Rust locally.
Fortunately, installing Rust is super easy :

$ curl https://sh.rustup.rs -sSf | sh

To get started, let’s just accept the defaults and install the stable version of Rust.

default host triple: x86_64-unknown-linux-gnu
default toolchain: stable (default)
profile: default
modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>

This gives us the compiler, the Cargo package manager, the API documentation, and the Rust Book.
When finished, a message announces us that the installation is complete.

Rust is installed now. Great!

$ rustup component add rust-docs

rustup

is the command you use to manage the Rust installation.
When a new stable version of Rust is available, you will simply type rustup update to update the installation.

$ rustup update

rustup doc will instead open the offline documentation in the system browser.

$ rustup doc

The full documentation can be found on Rust’s official website at https://www.rust-lang.org/learn

In the next article

we will discuss how Rust manages to secure memory allocation and then go into detail about the mechanisms of Data Ownership (Ownership), Borrowing (Borrowing) and Lifetime (Lifetime).