Abstractions

One aspect of any Rust application that holds it above other applications from other languages is that they are really fast and memory-safe. This is down to an ideal called a zero-cost abstraction. An abstraction is a way of hoisting a low-level construct higher, making it easier, safer, and more reliable. These are commonly seen in cross-platform libraries where a user interface has a common abstraction layer, so developers only need to say var n = new Label {Text = "Hello"}; to create a label for the UI without needing to know what is going on under the hood.

It is usual that abstractions cause some sort of penalties, meaning that code that uses abstractions would run slower or use more memory than corresponding lower-level code. In terms of Rust, these zero-cost abstractions mean that, in terms of computer resources, they cause no penalties. This is normally performed during compilation; the compiler generates the abstractions and executes them. Once done, the compiler will generate the best possible code.

This does have a problem—the compiler will object to code that the developer considers completely fine. This is because, as people, we don't think the same way as a language does, so what we consider as correct ownership is not how Rust considers it. Thankfully, as time goes on, and you use Rust more, this problem becomes far less of one.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset