Configuring our functions with traits
In a rust web program, we generally have a series of layers and APIs. In terms of layers, we generally have a frontend, backend, and data access layer. With these layers, we can have multiple different frameworks and engines. Throughout the book we will be building out our web application so we can swap these frameworks and engines out.
To be honest, I personally find strong preferences to a particular framework or library to be a little strange. These frameworks should have minimal footprint on your code, with clear separation between the interfaces. With web frameworks, you still must run a server using the web framework. We will solve this in the book, but for a good trick I like to exploit enabling us to swap out different engines and crates is traits with no reference to self
.
A trait with no reference to self
enables us to configure functions at compile time. To demonstrate how this works, we are going to add another endpoint and data contract...