Skip to content

Commit 93bd8d2

Browse files
authored
Merge pull request #34 from tomoikey/v0.5.19
V0.5.19
2 parents ef1fe16 + a6bb3ed commit 93bd8d2

File tree

10 files changed

+54
-1
lines changed

10 files changed

+54
-1
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ repository = "https://github.com/tomoikey/refined_type"
66
readme = "README.md"
77
categories = ["accessibility", "development-tools", "rust-patterns"]
88
license = "MIT"
9-
version = "0.5.18"
9+
version = "0.5.19"
1010
edition = "2021"
1111

1212
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

examples/1.rs

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use refined_type::rule::composer::{If, IfElse};
2+
use refined_type::rule::{
3+
EmailStringRule, EvenRuleU8, ExistsVecRule, ForAllVecRule, GreaterRuleU8, HeadVecRule,
4+
NonEmptyString, NonEmptyStringRule, NonEmptyVecRule,
5+
};
6+
use refined_type::{And, Refined};
7+
use serde::Deserialize;
8+
use std::fmt::Display;
9+
10+
impl Display for Data {
11+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12+
write!(
13+
f,
14+
"name: {}, age: {}, friends: {:?}",
15+
self.name, self.age, self.friends
16+
)
17+
}
18+
}
19+
20+
#[allow(clippy::type_complexity)]
21+
#[derive(Debug, Deserialize)]
22+
pub struct Data {
23+
name: NonEmptyString,
24+
age: Refined<If<GreaterRuleU8<10>, EvenRuleU8>>,
25+
friends: Refined<
26+
IfElse<
27+
And![ForAllVecRule<NonEmptyStringRule>, NonEmptyVecRule<String>],
28+
HeadVecRule<EmailStringRule>,
29+
ExistsVecRule<EmailStringRule>,
30+
>,
31+
>,
32+
}
33+
34+
fn main() {
35+
let data = r#"
36+
{
37+
"name": "John Doe",
38+
"age": 20,
39+
"friends": ["[email protected]", "Bob"]
40+
}
41+
"#;
42+
43+
let data: Data = serde_json::from_str(data).unwrap();
44+
println!("{}", data); // name: John Doe, age: 20, friends: Refined { value: ["[email protected]", "Bob"] }
45+
}

src/rule/collection/index.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::collections::VecDeque;
55
pub type Index<const INDEX: usize, RULE, ITERABLE> = Refined<IndexRule<INDEX, RULE, ITERABLE>>;
66
pub type IndexVec<const INDEX: usize, RULE> = Refined<IndexRuleVec<INDEX, RULE>>;
77

8+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
89
pub struct IndexRule<const INDEX: usize, RULE, ITERABLE>
910
where
1011
RULE: Rule,

src/rule/collection/reverse.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::marker::PhantomData;
77
pub type Reverse<RULE> = Refined<ReverseRule<RULE>>;
88

99
/// Rule where the data in the collection satisfies the condition after reversing
10+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
1011
pub struct ReverseRule<RULE>
1112
where
1213
RULE: Rule,

src/rule/collection/skip.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub type SkipVecDeque<RULE, OPTION> = Refined<SkipVecDequeRule<RULE, OPTION>>;
2121
pub type SkipString<RULE, OPTION> = Refined<SkipStringRule<RULE, OPTION>>;
2222

2323
/// Rule where the data in the collection satisfies the condition after skipping the first element
24+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
2425
pub struct SkipRule<RULE, ITERABLE, OPTION>
2526
where
2627
RULE: Rule,

src/rule/collection/skip/option/no_skip.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::rule::SkipOption;
22

3+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
34
pub struct NoSkip<T> {
45
_phantom_data: std::marker::PhantomData<T>,
56
}

src/rule/collection/skip/option/skip_even_index.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::rule::SkipOption;
22

3+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
34
pub struct SkipEvenIndex<ITEM> {
45
_phantom_data: std::marker::PhantomData<ITEM>,
56
}

src/rule/collection/skip/option/skip_first.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::rule::SkipOption;
22

3+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
34
pub struct SkipFirst<ITEM> {
45
_phantom_data: std::marker::PhantomData<ITEM>,
56
}

src/rule/collection/skip/option/skip_odd_index.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::rule::SkipOption;
22

3+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
34
pub struct SkipOddIndex<ITEM> {
45
_phantom_data: std::marker::PhantomData<ITEM>,
56
}

src/rule/string/regex.rs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub use regex::Regex;
2323
macro_rules! declare_regex_rule {
2424
($vis:vis $rule:ident, $regex:literal) => {
2525
$crate::paste::item! {
26+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
2627
$vis struct $rule<STRING> {
2728
_phantom: std::marker::PhantomData<STRING>,
2829
}

0 commit comments

Comments
 (0)