Skip to content

Commit 72a57c4

Browse files
committed
fix bug
1 parent 93bd8d2 commit 72a57c4

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

examples/1.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use refined_type::rule::composer::{If, IfElse};
1+
use refined_type::rule::composer::{If, IfElse, Not};
22
use refined_type::rule::{
33
EmailStringRule, EvenRuleU8, ExistsVecRule, ForAllVecRule, GreaterRuleU8, HeadVecRule,
4-
NonEmptyString, NonEmptyStringRule, NonEmptyVecRule,
4+
Ipv4AddrRule, LastVecRule, NonEmptyString, NonEmptyStringRule,
55
};
66
use refined_type::{And, Refined};
77
use serde::Deserialize;
@@ -24,9 +24,12 @@ pub struct Data {
2424
age: Refined<If<GreaterRuleU8<10>, EvenRuleU8>>,
2525
friends: Refined<
2626
IfElse<
27-
And![ForAllVecRule<NonEmptyStringRule>, NonEmptyVecRule<String>],
27+
And![
28+
ForAllVecRule<NonEmptyStringRule>,
29+
ExistsVecRule<Ipv4AddrRule<String>>
30+
],
2831
HeadVecRule<EmailStringRule>,
29-
ExistsVecRule<EmailStringRule>,
32+
LastVecRule<Not<EmailStringRule>>,
3033
>,
3134
>,
3235
}
@@ -36,10 +39,12 @@ fn main() {
3639
{
3740
"name": "John Doe",
3841
"age": 20,
39-
"friends": ["[email protected]", "Bob"]
42+
"friends": ["[email protected]", "192.168.11.1"]
4043
}
4144
"#;
4245

43-
let data: Data = serde_json::from_str(data).unwrap();
44-
println!("{}", data); // name: John Doe, age: 20, friends: Refined { value: ["[email protected]", "Bob"] }
46+
let data = serde_json::from_str::<Data>(data).map(|n| n.to_string());
47+
48+
// Ok("name: John Doe, age: 20, friends: Refined { value: [\"[email protected]\", \"192.168.11.1\"] }")
49+
println!("{:?}", data);
4550
}

src/rule/string/ipv4.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::str::FromStr;
77
pub type Ipv4Addr<STRING> = Refined<Ipv4AddrRule<STRING>>;
88

99
/// Rule where the target value must be a valid IPv4 address
10+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
1011
pub struct Ipv4AddrRule<T> {
1112
_phantom: std::marker::PhantomData<T>,
1213
}

src/rule/string/ipv6.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::str::FromStr;
77
pub type Ipv6Addr<STRING> = Refined<Ipv6AddrRule<STRING>>;
88

99
/// Rule where the target value must be a valid IPv6 address
10+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
1011
pub struct Ipv6AddrRule<T> {
1112
_phantom: std::marker::PhantomData<T>,
1213
}

0 commit comments

Comments
 (0)