2 Laying the foundation

 

This chapter covers

  • Getting to know the Rust types
  • Understanding the Rust ownership system
  • Implementing custom behavior in your own types
  • Understanding the building blocks of an asynchronous ecosystem
  • Choosing third-party libraries to build web services with Rust
  • Setting up a basic working web service with Rust

The first chapter provided a pretty good rundown of the features that come with Rust, and the tooling we need to add to be able to create web services with Rust. This chapter elaborates on these points. The first part details how to use the language to create your own types and functions. In the second part, you’ll add a web server so you can serve your first response to the user.

As mentioned before, you will fare best if you read chapters 1 to 6 of The Rust Programming Language (https://doc.rust-lang.org/book/). This chapter will teach the concepts needed for completing this book, so it might be enough to go through this chapter without any previous knowledge. However, I recommend again to go at least briefly through the first six chapters of The Rust Programming Language to have a proper foundation of the language itself.

2.1 Following the Rust playbook

2.1.1 Modeling your resources with structs

2.1.2 Understanding options

2.1.3 Using documentation to solve errors

2.1.4 Handling strings in Rust

2.1.5 Taking an excursion into moving, borrowing, and ownership

2.1.6 Using and implementing traits

2.1.7 Handling results

2.2 Creating our web server

2.2.1 Handling multiple requests at once

2.2.2 Rust’s asynchronous environment

2.2.3 Rust’s handling of async/await

2.2.4 Using Rust’s Future type