Custom Rules
Define a custom rule
This page explains how to create a custom rule.
Overview
You can create custom rules by implementing the Rule
trait.
This allows you to define rules that are not provided by the library.
Get Started
Let’s create a custom rule that only accepts strings that start with Hello
.
At first, define a struct for the custom rule.
Next, implement the Rule
trait for the struct.
Creating a type alias improves readability.
Now you can use the custom rule.
That’s all for creating custom rules! It’s very simple!
Now, if the standard provided rules aren’t sufficient, you can define your own rules!