Chapter 2. A Tour of Rust
Rust presents the authors of a book like this one with a challenge: what gives the language its character is not some specific, amazing feature that we can show off on the first page, but rather, the way all its parts are designed to work together smoothly in service of the goals we laid out in the last chapter: safe, performant systems programming. Each part of the language is best justified in the context of all the rest.
So rather than tackle one language feature at a time, weâve prepared a tour of a few small but complete programs, each of which introduces some more features of the language, in context:
-
As a warm-up, we have a program that does a simple calculation on its command-line arguments, with unit tests. This shows Rustâs core types and introduces traits.
-
Next, we build a web server. Weâll use a third-party library to handle the details of HTTP and introduce string handling, closures, and error handling.
-
Our third program plots a beautiful fractal, distributing the computation across multiple threads for speed. This includes an example of a generic function, illustrates how to handle something like a buffer of pixels, and shows off Rustâs support for concurrency.
-
Finally, we show a robust command-line tool that processes files using regular expressions. This presents the Rust standard libraryâs facilities for working with files, and the most commonly used third-party regular expression library.
Rustâs promise to prevent ...
Get Programming Rust, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.