Get Started
Quickstart
Let’s start by creating your first code using refined_type
.
Dependence
To handle JSON, let’s first add serde
and serde_json
to your project.
Or add the following to your Cargo.toml
:
Let’s get started
First, let’s envision a scenario where we validate incoming JSON data. For example, let’s say we want data that meets the following requirements.
name
field that is not empty.age
field that falls within the range of 18 to 80.friends
field containing at least one entry, each with a name that is not empty.
We can define the rules for each field as follows:
Valid JSON case
Now, let’s try to deserialize the valid JSON data.
The JSON data meets the requirements, so it is successfully deserialized.
Invalid JSON case
Next, let’s try to deserialize JSON data that does not meet the requirements.
name
field is empty
age
field is out of range
friends
field is empty
friends
field is not empty, but the name is empty
Summary
By defining rules for each field, you can easily validate JSON data.
This is just one example of how you can use refined_type
to enhance your types.
Enjoy a wonderful type life!