Skip to content

Commit

Permalink
Merge pull request #36 from tomoikey/v0.5.20
Browse files Browse the repository at this point in the history
Release v0.5.20
  • Loading branch information
tomoikey authored Nov 11, 2024
2 parents d83572f + 004ab3e commit 3969f57
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repository = "https://github.com/tomoikey/refined_type"
readme = "README.md"
categories = ["accessibility", "development-tools", "rust-patterns"]
license = "MIT"
version = "0.5.19"
version = "0.5.20"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -18,4 +18,4 @@ serde = { version = "1.0.214", features = ["derive"] }

[dev-dependencies]
anyhow = "1.0.92"
serde_json = "1.0.128"
serde_json = "1.0.128"
43 changes: 43 additions & 0 deletions src/rule/length/equal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,54 @@ use crate::Refined;
/// A type that holds a value satisfying the `LengthEqualRule`
pub type LengthEqual<const LENGTH: usize, ITEM> = Refined<LengthEqualRule<LENGTH, ITEM>>;

/// A type that holds a value satisfying the `LengthEqualVecRule`
pub type LengthEqualVec<const LENGTH: usize, ITEM> = Refined<LengthEqualVecRule<LENGTH, ITEM>>;

/// A type that holds a value satisfying the `LengthEqualVecDequeRule`
pub type LengthEqualVecDeque<const LENGTH: usize, ITEM> =
Refined<LengthEqualVecDequeRule<LENGTH, ITEM>>;

/// A type that holds a value satisfying the `LengthEqualHashMapRule`
pub type LengthEqualHashMap<const LENGTH: usize, K, V> =
Refined<LengthEqualHashMapRule<LENGTH, K, V>>;

/// A type that holds a value satisfying the `LengthEqualHashSetRule`
pub type LengthEqualHashSet<const LENGTH: usize, ITEM> =
Refined<LengthEqualHashSetRule<LENGTH, ITEM>>;

/// A type that holds a value satisfying the `LengthEqualStringRule`
pub type LengthEqualString<const LENGTH: usize> = LengthEqual<LENGTH, String>;

/// A type that holds a value satisfying the `LengthEqualStrRule`
pub type LengthEqualStr<'a, const LENGTH: usize> = LengthEqual<LENGTH, &'a str>;

/// Rule where the input `ITEM` has a length equal to `LENGTH`
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd)]
pub struct LengthEqualRule<const LENGTH: usize, ITEM> {
_phantom: std::marker::PhantomData<ITEM>,
}

/// Rule where the input `Vec` has a length equal to `LENGTH`
pub type LengthEqualVecRule<const LENGTH: usize, T> = LengthEqualRule<LENGTH, Vec<T>>;

/// Rule where the input `VecDeque` has a length equal to `LENGTH`
pub type LengthEqualVecDequeRule<const LENGTH: usize, T> =
LengthEqualRule<LENGTH, std::collections::VecDeque<T>>;

/// Rule where the input `HashMap` has a length equal to `LENGTH`
pub type LengthEqualHashMapRule<const LENGTH: usize, K, V> =
LengthEqualRule<LENGTH, std::collections::HashMap<K, V>>;

/// Rule where the input `HashSet` has a length equal to `LENGTH`
pub type LengthEqualHashSetRule<const LENGTH: usize, T> =
LengthEqualRule<LENGTH, std::collections::HashSet<T>>;

/// Rule where the input `String` has a length equal to `LENGTH`
pub type LengthEqualStringRule<const LENGTH: usize> = LengthEqualRule<LENGTH, String>;

/// Rule where the input `&str` has a length equal to `LENGTH`
pub type LengthEqualStrRule<'a, const LENGTH: usize> = LengthEqualRule<LENGTH, &'a str>;

impl<const LENGTH: usize, ITEM: LengthDefinition> Rule for LengthEqualRule<LENGTH, ITEM> {
type Item = ITEM;
fn validate(target: Self::Item) -> Result<Self::Item, Error<Self::Item>> {
Expand Down
43 changes: 43 additions & 0 deletions src/rule/length/grater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,54 @@ use crate::Refined;
/// A type that holds a value satisfying the `LengthGreaterRule`
pub type LengthGreater<const THAN: usize, ITEM> = Refined<LengthGreaterRule<THAN, ITEM>>;

/// A type that holds a value satisfying the `LengthGreaterVecRule`
pub type LengthGreaterVec<const THAN: usize, ITEM> = Refined<LengthGreaterVecRule<THAN, ITEM>>;

/// A type that holds a value satisfying the `LengthGreaterVecDequeRule`
pub type LengthGreaterVecDeque<const THAN: usize, ITEM> =
Refined<LengthGreaterVecDequeRule<THAN, ITEM>>;

/// A type that holds a value satisfying the `LengthGreaterHashMapRule`
pub type LengthGreaterHashMap<const THAN: usize, K, V> =
Refined<LengthGreaterHashMapRule<THAN, K, V>>;

/// A type that holds a value satisfying the `LengthGreaterHashSetRule`
pub type LengthGreaterHashSet<const THAN: usize, ITEM> =
Refined<LengthGreaterHashSetRule<THAN, ITEM>>;

/// A type that holds a value satisfying the `LengthGreaterStringRule`
pub type LengthGreaterString<const THAN: usize> = LengthGreater<THAN, String>;

/// A type that holds a value satisfying the `LengthGreaterStrRule`
pub type LengthGreaterStr<'a, const THAN: usize> = LengthGreater<THAN, &'a str>;

/// Rule where the input `ITEM` has a length greater than `THAN`
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd)]
pub struct LengthGreaterRule<const THAN: usize, ITEM> {
_phantom: std::marker::PhantomData<ITEM>,
}

/// Rule where the input `Vec` has a length greater than `THAN`
pub type LengthGreaterVecRule<const THAN: usize, ITEM> = LengthGreaterRule<THAN, Vec<ITEM>>;

/// Rule where the input `VecDeque` has a length greater than `THAN`
pub type LengthGreaterVecDequeRule<const THAN: usize, ITEM> =
LengthGreaterRule<THAN, std::collections::VecDeque<ITEM>>;

/// Rule where the input `HashMap` has a length greater than `THAN`
pub type LengthGreaterHashMapRule<const THAN: usize, K, V> =
LengthGreaterRule<THAN, std::collections::HashMap<K, V>>;

/// Rule where the input `HashSet` has a length greater than `THAN`
pub type LengthGreaterHashSetRule<const THAN: usize, ITEM> =
LengthGreaterRule<THAN, std::collections::HashSet<ITEM>>;

/// Rule where the input `String` has a length greater than `THAN`
pub type LengthGreaterStringRule<const THAN: usize> = LengthGreaterRule<THAN, String>;

/// Rule where the input `&str` has a length greater than `THAN`
pub type LengthGreaterStrRule<'a, const THAN: usize> = LengthGreaterRule<THAN, &'a str>;

impl<const THAN: usize, ITEM: LengthDefinition> Rule for LengthGreaterRule<THAN, ITEM> {
type Item = ITEM;
fn validate(target: Self::Item) -> Result<Self::Item, Error<Self::Item>> {
Expand Down
40 changes: 40 additions & 0 deletions src/rule/length/less.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,51 @@ use crate::Refined;
/// A type that holds a value satisfying the `LengthLessRule`
pub type LengthLess<const THAN: usize, ITEM> = Refined<LengthLessRule<THAN, ITEM>>;

/// A type that holds a value satisfying the `LengthLessVecRule`
pub type LengthLessVec<const THAN: usize, ITEM> = Refined<LengthLessVecRule<THAN, ITEM>>;

/// A type that holds a value satisfying the `LengthLessVecDequeRule`
pub type LengthLessVecDeque<const THAN: usize, ITEM> = Refined<LengthLessVecDequeRule<THAN, ITEM>>;

/// A type that holds a value satisfying the `LengthLessHashMapRule`
pub type LengthLessHashMap<const THAN: usize, K, V> = Refined<LengthLessHashMapRule<THAN, K, V>>;

/// A type that holds a value satisfying the `LengthLessHashSetRule`
pub type LengthLessHashSet<const THAN: usize, ITEM> = Refined<LengthLessHashSetRule<THAN, ITEM>>;

/// A type that holds a value satisfying the `LengthLessStringRule`
pub type LengthLessString<const THAN: usize> = LengthLess<THAN, String>;

/// A type that holds a value satisfying the `LengthLessStrRule`
pub type LengthLessStr<'a, const THAN: usize> = LengthLess<THAN, &'a str>;

/// Rule where the input `ITEM` has a length less than `THAN`
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd)]
pub struct LengthLessRule<const THAN: usize, ITEM> {
_phantom: std::marker::PhantomData<ITEM>,
}

/// Rule where the input `Vec` has a length less than `THAN`
pub type LengthLessVecRule<const THAN: usize, ITEM> = LengthLessRule<THAN, Vec<ITEM>>;

/// Rule where the input `VecDeque` has a length less than `THAN`
pub type LengthLessVecDequeRule<const THAN: usize, ITEM> =
LengthLessRule<THAN, std::collections::VecDeque<ITEM>>;

/// Rule where the input `HashMap` has a length less than `THAN`
pub type LengthLessHashMapRule<const THAN: usize, K, V> =
LengthLessRule<THAN, std::collections::HashMap<K, V>>;

/// Rule where the input `HashSet` has a length less than `THAN`
pub type LengthLessHashSetRule<const THAN: usize, ITEM> =
LengthLessRule<THAN, std::collections::HashSet<ITEM>>;

/// Rule where the input `String` has a length less than `THAN`
pub type LengthLessStringRule<const THAN: usize> = LengthLessRule<THAN, String>;

/// Rule where the input `&str` has a length less than `THAN`
pub type LengthLessStrRule<'a, const THAN: usize> = LengthLessRule<THAN, &'a str>;

impl<const THAN: usize, ITEM: LengthDefinition> Rule for LengthLessRule<THAN, ITEM> {
type Item = ITEM;
fn validate(target: Self::Item) -> Result<Self::Item, Error<Self::Item>> {
Expand Down

0 comments on commit 3969f57

Please sign in to comment.