You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+66-43
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,18 @@
1
1
# Refined-Type
2
-
**refined-type** is a library developed for Rust. It enhances your types, making them more robust and expanding the range of guarantees your applications can statically ensure.
2
+
3
+
**refined-type** is a library developed for Rust. It enhances your types, making them more robust and expanding the
4
+
range of guarantees your applications can statically ensure.
3
5
4
6
# Overview
5
-
You can create various rules for a certain type, such as phone numbers, addresses, times, and so on.
6
-
Once you have established the rules, you can easily combine them.
7
-
Specifically, if you create rules for 'non-empty strings' and 'strings composed only of alphabets,' you do not need to redefine a new rule for 'non-empty strings composed only of alphabets'.
7
+
8
+
You can create various rules for a certain type, such as phone numbers, addresses, times, and so on.
9
+
Once you have established the rules, you can easily combine them.
10
+
Specifically, if you create rules for 'non-empty strings' and 'strings composed only of alphabets,' you do not need to
11
+
redefine a new rule for 'non-empty strings composed only of alphabets'.
8
12
All rules can be arbitrarily combined and extended as long as the target type matches. Enjoy a wonderful type life!
9
13
10
14
# Example Usage
15
+
11
16
```rust
12
17
typeNonEmptyString=Refined<NonEmptyStringRule>;
13
18
@@ -21,15 +26,17 @@ fn main() {
21
26
```
22
27
23
28
# Installation
29
+
24
30
```shell
25
31
cargo add refined-type
26
32
```
27
33
28
34
# Custom Rule
29
-
There are many situations where you may want to define custom rules.
30
-
To define rules for a specific target type, you first need to define a struct.
31
-
In the struct, define fields for specifying detailed conditions.
32
-
Once the definition is complete, all you need to do is implement the Rule trait.
35
+
36
+
There are many situations where you may want to define custom rules.
37
+
To define rules for a specific target type, you first need to define a struct.
38
+
In the struct, define fields for specifying detailed conditions.
39
+
Once the definition is complete, all you need to do is implement the Rule trait.
Err(Error::new(format!("{} does not end with `John`", target)))
175
190
}
176
191
}
@@ -187,8 +202,13 @@ fn main() {
187
202
```
188
203
189
204
# JSON
190
-
`refined_type` is compatible with `serde_json`. This ensures type-safe communication and eliminates the need to write new validation processes. All you need to do is implement a set of rules once and implement `serde`’s `Serialize` and `Deserialize`.
205
+
206
+
`refined_type` is compatible with `serde_json`. This ensures type-safe communication and eliminates the need to write
207
+
new validation processes. All you need to do is implement a set of rules once and implement `serde`’s `Serialize`
I have implemented the `Add` trait for a part of the `Refined` that I provided. Therefore, operations can be performed without downgrading the type level.
329
+
330
+
I have implemented the `Add` trait for a part of the `Refined` that I provided. Therefore, operations can be performed
0 commit comments