Creative Projects for Rust Programmers
Build exciting projects on domains such as web apps, WebAssembly, games, and parsing
Carlo Milanesi
- 404 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Creative Projects for Rust Programmers
Build exciting projects on domains such as web apps, WebAssembly, games, and parsing
Carlo Milanesi
About This Book
A practical guide to understanding the latest features of the Rust programming language, useful libraries, and frameworks that will help you design and develop interesting projects
Key Features
- Work through projects that will help you build high-performance applications with Rust
- Delve into concepts such as error handling, memory management, concurrency, generics, and macros with Rust
- Improve business productivity by choosing the right libraries and frameworks for your applications
Book Description
Rust is a community-built language that solves pain points present in many other languages, thus improving performance and safety. In this book, you will explore the latest features of Rust by building robust applications across different domains and platforms.
The book gets you up and running with high-quality open source libraries and frameworks available in the Rust ecosystem that can help you to develop efficient applications with Rust. You'll learn how to build projects in domains such as data access, RESTful web services, web applications, 2D games for web and desktop, interpreters and compilers, emulators, and Linux Kernel modules. For each of these application types, you'll use frameworks such as Actix, Tera, Yew, Quicksilver, ggez, and nom. This book will not only help you to build on your knowledge of Rust but also help you to choose an appropriate framework for building your project.
By the end of this Rust book, you will have learned how to build fast and safe applications with Rust and have the real-world experience you need to advance in your career.
What you will learn
- Access TOML, JSON, and XML files and SQLite, PostgreSQL, and Redis databases
- Develop a RESTful web service using JSON payloads
- Create a web application using HTML templates and JavaScript and a frontend web application or web game using WebAssembly
- Build desktop 2D games
- Develop an interpreter and a compiler for a programming language
- Create a machine language emulator
- Extend the Linux Kernel with loadable modules
Who this book is for
This Rust programming book is for developers who want to get hands-on experience with implementing their knowledge of Rust programming, and are looking for expert advice on which libraries and frameworks they can adopt to develop software that typically uses the Rust language.
Frequently asked questions
Information
- Defining a programming language using a formal grammar
- Classifying programming languages into three categories
- Learning two popular techniques for building parsers—compiler-compilers and parser combinators
- Using a parser combinator library for Rust named Nom
- Processing a source code to check its syntax following a context-free grammar, using the Nom library (calc_parser)
- Verifying the consistency of variable declarations and their usage in some source code, and at the same time preparing the required structure for optimal execution of the code (calc_analyzer)
- Executing the preprocessed code, in a process named interpretation (calc_interpreter)
- Translating the preprocessed code into another programming language, in a process named compilation (calc_compiler); as an example, translation to Rust code will be shown
Technical requirements
Project overview
- The first project (calc_parser) will just be a syntax checker for the Calc language. Actually, it is just a parser, followed by a formatted debugging print of the parsing result.
- The second project (calc_analyzer) uses the parsing result of the first project to add the verification of the consistency of the variable declarations and of their usage, followed by a formatted debugging print of the analysis result.
- The third project (calc_interpreter) uses the analysis result to execute the preprocessed code, in an interactive interpreter.
- The fourth project (calc_compiler) uses the analysis result again to translate the preprocessed code into equivalent Rust code.
Introducing Calc
@first
@second
> first
> second
@sum
sum := first + second
< sum
< first * second
- The first two statements (@first and @second) declare two variables. Any variable in Calc represents a 64-bit floating-point number.
- The third and fourth statements (> first and > second) are input statements. Each of these prints a question mark and waits for the user to type a number and press Enter. Such a number, if valid, is stored in the specified variable. If no number or an invalid number is typed before pressing Enter, the value 0 is assigned to the variable.
- The fifth statement declares the sum variable.
- The sixth statement (sum := first + second) is a Pascal-style assignment. It computes the sum of the first and second variables and assigns the result to the sum variable.
- The seventh and eight statements perform output. The seventh statement (< sum) prints on the console the current value of the sum variable. The eighth statement (< first * second) computes the multiplication between the current values of the first and second variables, and then prints on the console the result of such multiplication.
y := m * x + q
a := a + b - c / d
a := 2.1 + 4 * 5
a := (2.1 + 4) * 5
@first@second>first>second@sum sum:=first+second<sum<first*second
- The whole text is a program.
- Any program is a sequence of statements. In the first example program, there is exactly one statement for each line.
- In some statements, there can be an arithmetic formula that can be evaluated, such as a * 3 + 2. This formula is an expression.
- Any expression can contain sums or subtractions of simpler expressions. The simpler expressions that contain neither sums nor subtractions are named terms. Therefore, any expression can be a term (if it contains neither sums nor subtractions), or it can be the sum of an expression and a term, or it can be the subtraction of an expression and a term.
- Any term can contain multiplications or divisions of simpler expressions. The simpler expressions that contain neither multiplications nor divisions are named factors. Therefore, any term can be a factor (if it contains neither multiplications nor divisions), or it can be the multiplication of a term and a factor, or it can be the division of a term and a factor. There are three possible kinds of factors, l...