This post briefly talks about how to create functions that accept struct instances that implement a specific trait.
Actix-Web: The Most Fun Rust Web Framework Is Back!
The most fun Rust web framework is back with a new project leader! I feel relieved by its comeback. Today, I was trying out one of the alternatives to Actix-web. But I was having difficulties making it read and parse
Why You Should Choose Rust Stable Over Nightly
If you are new to Rust, choose Rust Stable over Nightly to make your life and other people’s lives simple – may apply to both crate producers and consumers. There are three types of Rust compiler – Nightly, Beta, and
Vec With Specific Trait Type
In this post, we want to create a Vec instance that only accepts struct instances that implements a particular trait.
Actix-Web With MySQL Using R2D2 For Connection Pool
R2D2 is a connection pool for Rust applications, e.g., Actix-Web, that use databases like MySQL. Opening and closing a database connection is an expensive operation. With connection pooling, the database connection creation happens once, and the application can reuse it
How to use Strategy Design Pattern in Rust
This Design Pattern replaces a behavior with different implementation at run-time or sometimes at load-time by means of configuration. Two entities could have different implementations of the same behavior.
How to use Command Design Pattern in Rust
This Design Pattern uses commands to wrap and invoke capabilities. A car can run faster and slower. We can have commands AccelerateCommand and DecelerateCommand for increasing and decreasing speed, respectively. We can also have AccelerateAndDecelerateCommand to run both capabilities in a certain order.
How to use State Design Pattern in Rust
Anything has a state. An entity has a state. Similarly, a car can be in a state of acceleration. While it is accelerating, there are some things it certainly cannot or should not do, e.g., reversing at that very moment. The State Design Pattern treats each state as a struct whose functions represent movements to the other states.
How to Read Input from Console Examples
In Rust, we can read user inputs from the command-line console. These inputs are string values with newline characters at the end. Most of the time, we do not want those extra characters. This post provides three simple example codes
Using #[non_exhaustive] for Non-exhaustive Enums
Using non-exhaustive enums in one crate prevents codes in other crates from listing all the possible matches in a match expression. It forces developers to use wildcards for future-proofing.