Even though a wide variety of pro­gram­ming languages already exist – from C++ to Pascal, to Java – more are being developed all the time. These are supposed to be either simpler, securer or faster. The pro­gram­ming language Rust pursues all three ob­ject­ives equally and has been very suc­cess­ful at it. According to a survey of users of the developer platform Stack Overflow, Rust was the most popular pro­gram­ming language in 2019.

What is Rust?

The Rust pro­gram­ming language was developed by Mozilla in 2010. The language was first pursued as a hobby project by an in­di­vidu­al developer and then used to develop a browser engine for Firefox. The project has since become open-source and is being pursued up by an active community; however, the project still receives financial support from Mozilla.

Falling somewhere between lower-level C languages and high-ab­strac­tion languages such as Java, Rust is actually a pro­gram­ming language used for system pro­gram­ming. This type of language allows operating systems or ap­plic­a­tions – those that are closely in­ter­leaved with Windows, Linux, or macOS – to be im­ple­men­ted. At the same time, however, Rust is utilised at a much smaller level in the pro­gram­ming of web ap­plic­a­tions.

Rust language: special features

The biggest advantage of Rust in com­par­is­on with other pro­gram­ming languages lies in its security. This is achieved partially through error man­age­ment. Should an error occur during com­pil­a­tion that cannot be fixed, the ap­pro­pri­ately-named “panic!” macro is launched. This shuts down the program and provides an error no­ti­fic­a­tion so that no damage can arise.

Rust’s memory man­age­ment is secure as well. The advantage is that Rust achieves memory safety without a garbage collector. In many pro­gram­ming languages, memory has been a popular point of attack for hackers. When the memory fills up, this can lead to errors in the system, and as a result, a weakness that can be exploited. A “garbage collector” ensures that un­ne­ces­sary items disappear from memory. This, however, slows the speed of the code when it is run. The Rust compiler makes the “garbage collector” obsolete. Instead, it checks during com­pil­a­tion if there could be an error in the memory.

The strong security features, however, do not exactly come at the cost of per­form­ance. Rust is a language for system pro­gram­ming, like C/C++, and also provides the same speed when it is run. On the one hand that has to do with the eschewal of a “garbage collector.” Fast runtime is also ensured by “zero cost ab­strac­tion”, which means that you can have the comfort of pro­gram­ming in a language with high levels of ab­strac­tion without dealing with declines in per­form­ance.

This makes Rust a mix of high-level and low-level pro­gram­ming languages. Like C/C++, Rust is close to the hardware, which ensures high speed, while being just as easy to program as high-level languages.

Both beginners and ex­per­i­enced pro­gram­mers can get to grips with Rust quickly. In the way it is used, the language is close to es­tab­lished al­tern­at­ives. A big advantage, however, lies in the amount of effort that went into the design of the error no­ti­fic­a­tions. Where other pro­gram­ming languages only display errors cryptic­ally, Rust provides practical and helpful in­struc­tions for how one can fix them.

Tip

Rust is one of the pro­gram­ming languages that is strongly supported by WebAssembly. As a result, Rust is also used to develop fast ap­plic­a­tions for the web.

Rust pro­gram­ming: syntax basics (with example)

At a first glance, Rust’s syntax is very similar to that of C or C++, which are also system pro­gram­ming languages. The same basic features such as functions, loops, queries, constants, and variables are present here. Although the exact placement of brackets differs somewhat from that in some older languages, their use is similar. Rust, of course, does have some of its own features:

  • New functions are defined by the “fn” command.
  • The language works alongside macros that are char­ac­ter­ised by an ex­clam­a­tion point at the end of the term.
  • Variables can be defined with “let”; so that the data can be changed, however, this must be ex­pli­citly au­thor­ised with “mut”.
  • Rust also has a special ownership feature.

In Rust syntax, ownership is the re­la­tion­ship of a variable to its value. The exception lies in the fact that a specific value can only belong to one variable. If the value is changed, the variable is no longer usable:

fn main() {
    let hello = String::from("Hello, world!");
    let hello1 = hello;
    println!("{}", hello);
}

This code won’t work, because the content of “hello” was trans­ferred to “hello1” so it can’t be called up again in the macro. Instead, the new variable needs to be used in the last command, which then leads to the correct output.

fn main() {
    let hello = String::from("Hello, world!");
    let hello1 = hello;
    println!("{}", hello1);
}
Summary

As well as being simple to use, Rust offers more security and higher per­form­ance. Though it is true that the pro­gram­ming language isn’t ground-breaking in­nov­at­ive, it builds upon known and loved languages like C/C++ while offering in­ter­est­ing new features. It’s not hard to make the switch if you’re already familiar with other languages.

If you would like to have a go at using this modern pro­gram­ming language, follow the steps in our Rust tutorial.

Go to Main Menu