HttpServer::
is the main backbone to the project, it handles all the transport layer details
App::
is where the app logic lives:
- routes
- middleware
- request handlers
- etc.
Each request handler is set up in the same way for actix-web
- an async function that takes a
HttpRequest
returns aResponder
that returns something that implements the ability to turn into anHttpResponse
.
our run
function is defined in another file (lib.rs)
but why do we have tokio there?
tokio helps our main function be asynchronous
Asynchronous programming in Rust relies on the Future trait.
Future traits stand for a value that might not be there yet.
values that impl. the future trait expose a polling method that allows the program to check in on the status of the Future.
if you don’t poll a future there is no guarantee that the future will resolve. (lazy polling)
#[tokio::main]
is a macro. macro’s take in code (or a bunch of characters) and then transform or add code to the characters and then pass that code to the compiler at compile time.
you can use cargo expand
to stop the macros from going to the compiler so you can see what is going on in the macro under-the-hood.