Books
Ivo Balbaert

Rust Essentials

  • Евгений Корнюшенкоhas quoted2 years ago
    The infamous goto from C does not exist in Rust!
  • Евгений Корнюшенкоhas quoted2 years ago
    The heap is a much larger memory part than the stack, so it is important that memory locations are freed as soon as they are no longer needed. The Rust compiler sees when a variable ends its lifetime (or in other words, goes out of scope) and inserts a code at compile time to free its memory when the code is executed. This behavior is unique to Rust and is not present in other commonly used languages.
  • Евгений Корнюшенкоhas quoted2 years ago
    The website at https://crates.io/ is the central repository for Rust packages or crates (as they are called)
  • Евгений Корнюшенкоhas quoted2 years ago
    Step 2 has also produced a file named Cargo.lock; this is used by Cargo to keep track of dependencies in your application. At the moment, the application only contains:

    [root]
    name = "welcomec"
    version = "0.0.1"
    The same file format is used to lock down the versions of libraries or packages that your project depends on. If your project is built in the future when updated versions of the libraries are available, Cargo will make sure that only the versions recorded in Cargo.lock are used so that your project is not built with an incompatible version of a library. This ensures a repeatable build process
  • Евгений Корнюшенкоhas quoted2 years ago
    The file Cargo.toml (with capital C) is the configuration file or manifest of your project; it contains all the metadata that Cargo needs to compile your project. It follows the so-called TOML format (for more details about this format, go to https://github.com/toml-lang/toml) and contains the following text with information about our project
  • Евгений Корнюшенкоhas quoted2 years ago
    Cargo is Rust's package and dependency manager, and it is similar to Bundler, npm, pub, or pip for other languages. Although you can write Rust programs without it, Cargo is nearly indispensable for any large project; it works the same whether you work on a Windows, Linux, or a Mac OS X system. The installation procedure from the previous section includes the Cargo tool, so Rust is shipped with tooling included.

    Cargo does the following things for you:

    It makes a tidy folder structure and some templates for your project with the cargo new command
    It compiles (builds) your code by using the cargo build command
    It runs your project by using cargo run
    If your project contains unit tests, it can execute them for you by using cargo test
    If your project depends on packages, it will download them and build these packages according to the needs of your code by using cargo update
    We'll introduce how to use Cargo now, and we'll come back to it later, but you can find more info here: http://doc.crates.io/guide.html
  • Евгений Корнюшенкоhas quoted2 years ago
    Rust is especially suited when code quality is important, that is for:

    Modestly-sized or larger developer teams
    Code for long-running production use
    Code with a longer lifetime that requires regular maintenance and refactoring
    Code for which you would normally write a lot of unit tests to safeguard it
  • Евгений Корнюшенкоhas quoted2 years ago
    It is clear from the previous sections that Rust can be used in projects that normally use C or C++. Indeed, many regard Rust as a successor or a replacement of C and C++. Although Rust is designed to be a systems language, it has a broad range of possible applications due to its richness of constructs, making it an ideal candidate for applications that fall into one or all of the following categories:

    Client applications, such as browsers
    Low-latency, high-performance systems, such as device drivers, games, and signal processing
    Highly distributed and concurrent systems, such as server applications
    Real-time and critical systems, such as operating systems or kernels
    Embedded systems (that require a very minimal runtime footprint) or a resource-constrained environment, such as a Raspberry Pi, Arduino, or robotics
    Tools or services that can't support the long warm-up delays that are common in Just In Time (JIT) compiler systems and need instantaneous startup
    Web frameworks
    Large-scale, high-performance, resource intensive, and complex software systems
  • Евгений Корнюшенкоhas quoted2 years ago
    Other Rust characteristics that will be discussed in more detail in later chapters are as follows:

    Its variables are immutable by default (see Chapter 2, Using Variables and Types)
    Enums (see Chapter 4, Structuring Data and Matching Patterns)
    Pattern matching (see Chapter 4, Structuring Data and Matching Patterns)
    Generics (see Chapter 5, Generalizing Code with Higher-order Functions and Parametrization)
    Higher-order functions and closures (see Chapter 5, Generalizing Code with Higher-order Functions and Parametrization)
    The interface system called traits (see Chapter 5, Generalizing Code with Higher-order Functions and Parametrization)
    A hygienic macro system (see Chapter 7, Organizing Code and Macros)
    Zero-cost abstractions, which means that Rust has higher-language constructs, but these do not have an impact on performance
    In conclusion, Rust gives you ultimate power over memory allocation as well as removing many security and stability problems that are commonly associated with native languages
  • Евгений Корнюшенкоhas quoted2 years ago
    The rustc compiler is completely self hosted, which means that it is written in Rust and can compile itself by using a previous version. It uses the LLVM compiler framework as its backend (for more information on LLVM compiler framework, go to http://en.wikipedia.org/wiki/LLVM) and produces natively executable code that runs blazingly fast because it compiles to the same low-level code as C++ (To see an example of its speed, go to http://benchmarksgame.alioth.debian.org/u64q/rust.php.).
fb2epub
Drag & drop your files (not more than 5 at once)