What is Rust for?

Rust

Rust is a system programming language. It runs blazingly fast, prevents almost all crashes and removes the ambiguities associated with sharing access to data. Mozilla developed it as a tool to create a new generation browser engine – Servo.

Similar Facilities

The given language definition sounds like a fairy tale, since the henceforth tools have always balanced between speed and reliability. At one point, C++, in which speed and facilities are compensated by constant access errors outside the allocated memory to the reclamated memory. Or the unexpected results of reading data that is being written in-parallel by another thread. On the other hand, there’s Haskell, a “stronghold” language (on the principle “since it compiles, it operates”), which can’t brag about speed, though. Somewhere in-between balance Java, Python, C# and other popular (due to their usability) languages. As for me, Rust is a successful crossing of the best C++ and Haskell facilities. It keeps usability at the level of competitors.

Rust features similar with C++:

  • You don’t pay for things you don’t use. The code beauty doesn’t require performance sacrifices.
  • Predictable memory allocation and deallocation (RAII).
  • Multi-paradigmality. Even if it has a small tendency towards functionality.
  • Co-existence with libraries written in C/C++: ability to call C code and be called as well.
  • Minimal requirements to the environment (runtime). It’s possible to write a code of any level and size.

Rust features similar with Haskell:

Reasons why Rust can be faster than C++:

  • Aliasing information available to compiler (automatic __restrict)
  • One less jump on virtual functions due to traits (Runtime polymorphism)
  • Undefined struct layout
  • Reference counting (Rc) is lock-free because of being task-local
  • Allocator model: rust provides hints and could inline calls to jemalloc (issue, RFC)

Ad Astra per Aspera

All the Rust magic becomes possible thanks to the compiler knowledge about the owner of a particular entity (owner), the one borrowing it for some time (mutable borrow) and the one came to take a look at it (immutable borrow). When programming in C++ or Java, you keep in mind this information anyway, even if in some other form. In the Rust language constructions express it. This allows the compiler to verify the accuracy of your model and guarantee its unproblematic execution. We need a bit different approach for such programming. I’ll review the basic things that may confuse you when learning the language:

  1. There’s no inheritance. But there’re structures and traits.
  2. There’re pointers in the unsafe code only (unsafe {}). There are references in the code instead of them. They point to the existing objects for sure.
  3. If you have an invariable reference to something (immutable borrow = &Object), no one can change it while the reference is active.
  4. If you have a variable reference (mutable borrow = &mut Object), no one other can read the object content while the reference is active.
  5. The language developers prefer Mac and *nix. Therefore, we’re going to need GNU environment for the operation on Windows.

Rust has a very cheerful and active community. You’re always welcome at IRC channel and on Reddit. Quite a lot of good projects have been written. Most of them are actively developing at GitHub. The language is especially popular among developers of games and graphics. There’re early stages of operating systems. In the long term there’s a possibility of executing on web-servers and clients. Rust is suitable for any task!

Perhaps, the most serious problem today is its rapid growth. The syntax may change from one version to another. Sometimes you need to rethink the logic when adjusting to new language facilities. This situation will take place during this year, till Rust-1.0 is released. Meanwhile, Rust ‘n Stuffs magazine informs us about all the actual and future changes, with new articles and attractive projects in its weekly column.

Comments

1,128

Ropes — Fast Strings

Most of us work with strings one way or another. There’s no way to avoid them — when writing code, you’re doomed to concatinate strings every day, split them into parts and access certain characters by index. We are used to the fact that strings are fixed-length arrays of characters, which leads to certain limitations when working with them. For instance, we cannot quickly concatenate two strings. To do this, we will at first need to allocate the required amount of memory, and then copy there the data from the concatenated strings.