-
Book Overview & Buying
-
Table Of Contents
Design Patterns and Best Practices in Rust
By :
The most important architectural principle in Rust is designing systems where data flows in clear, predictable directions. Unidirectional, downward data flow minimizes complexity and bugs. This was true in Java, Python, C++, and every other language. The difference is that those languages allow you to ignore this principle. Rust doesn't.
When bidirectional communication is needed (such as consumer acknowledgments), the solution is to create a separate downward channel rather than allowing data to flow back upstream.
Let's build our producer/consumer system with clear directional flow: producers send messages down to the broker, which delivers them down to consumers.

Figure 9.1: Samsa's unidirectional data flow
To implement this flow, we need a data structure that can travel through each layer unchanged. Our core Message type represents data flowing through the system. Let's build it step...