Book Image

Rust Essentials

By : Ivo Balbaert
Book Image

Rust Essentials

By: Ivo Balbaert

Overview of this book

<p>Starting by comparing Rust with other programming languages, this book will show you where and how to use Rust. It will discuss primitive types along with variables and their scope, binding and casting, simple functions, and ways to control execution flow in a program.</p> <p>Next, the book covers flexible arrays, vectors, tuples, enums, and structs. You will then generalize the code with higher-order functions and generics applying it to closures, iterators, consumers, and so on. Memory safety is ensured by the compiler by using references, pointers, boxes, reference counting, and atomic reference counting. You will learn how to build macros and crates and discover concurrency for multicore execution.</p> <p>By the end of this book, you will have successfully migrated to using Rust and will be able to use it as your main programming language.</p>
Table of Contents (17 chapters)
Rust Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Other resources for learning Rust


This book has nearly covered all the topics of the so-called Book (http://doc.rust-lang.org/book/), and sometimes, it even went beyond. Nevertheless, the Book on the Rust website can still be a good resource to find the latest information, together with the fine collection of Rust code examples at http://rustbyexample.com/, which can be reached through the More examples link on Rust's homepage. For the most complete, in-depth information, refer to the reference at http://doc.rust-lang.org/reference.html.

Asking questions or following and commenting on the discussions on Reddit (https://www.reddit.com/r/rust) and Stack Overflow (https://stackoverflow.com/questions/tagged/rust) can also help you. Last but not the least, when you have an urgent Rust question, you can chat with the friendly experts on the IRC channel at https://client01.chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust.

A resource with coding guidelines on Rust can be found at http://doc.rust-lang.org/nightly/style/.

24 days of Rust is a highly recommended article series by Zbigniew Siciarz on a multitude of advanced Rust subjects; you can take a look at the index at https://siciarz.net/24-days-of-rust-conclusion/.

Files and databases

The standard library offers the std::io::fs module for filesystem manipulation:

  • If you have to work with comma separated values (CSV) files, use one of the available crates, such as simple_csv, csv, or xsv. The articles at https://siciarz.net/24-days-of-rust-csv/ can get you started.

  • For working with JSON files, use a crate such as rustc-serialize or json_macros; start with reading the information at https://siciarz.net/24-days-of-rust-working-json/.

  • For the XML format, there are plenty of possibilities, such as the rust-xml and the xml-rs crates.

For databases, there are crates available for working with the following technologies:

Graphics and games

Its high performance and low-level capabilities make Rust an ideal choice in the field of graphics and games. Searching for graphics reveals bindings for OpenGL (with packages gl-rs, glfw-sys), Core Graphics (with packages gfx, gdk), and others.

On the game front, there are game engines for Piston and chipmunk 2D and bindings for SDL1, SDL2, and Allegro5. A crate for a simple 3D game engine is kiss3d. A number of physics (ncollide) and math (nalgebra and cgmath-rs) crates exist that can be of use here.

Web development

A general overview of the status in this domain can be found at http://arewewebyet.com/. The most advanced and stable crate for developing HTTP applications at this moment is hyper. It is fast and contains both an HTTP client and a server to build complex web applications. To get started with it, read the introductory article at https://siciarz.net/24-days-of-rust-hyper/.

The HTTP client libraries built on top of hyper are rust-request and rest_client. A new Rust HTTP Toolkit project is emerging under the name teepee (http://teepee.rs/). It looks promising, but it was in its infancy at the time of writing this book.

For web frameworks, the best usable project is iron. If you only need a light micro web framework, rustful could be your choice. If you need a Representational State Transfer (REST) framework, go for rustless. Another useful web framework, which is still under active development, is nickel (http://nickel.rs/).

And of course, you must not ignore the new servo browser that is emerging!

Furthermore, crates exist for a lot of other categories such as functional and embedded programming (http://spin.atomicobject.com/2015/02/20/rust-language-c-embedded/), data structures, image processing (the image crate), audio, compression, encoding and encryption (rust-crypto and crypto), regular expressions, parsing, hashing, tooling, testing, template engines, and so on. You can take a look at the Rust-CI repository or the Awesome Rust compilation; you can refer to the links in the The ecosystem of crates section to get an idea of what is available. Zinc (http://zinc.rs/) is an example of a project that uses Rust to write a code stack for processors (at the moment, for ARM).

This brings us to the end of our Rust journey in this book. We hope you enjoyed it as much as we enjoyed writing it. You now have a firm foundation to start developing using Rust. We also hope that this quick overview has shown you why Rust is a rising star in the software development world, and that you will use it in your projects. Join the Rust community and start using your coding talents. Perhaps we'll meet again in the Rust(un)iverse.