use super::combinators::And;
use super::predicates::collection::MaxSize;
use super::predicates::numeric::{InRange, Negative, NonNegative, NonZero, Positive};
use super::predicates::string::{MaxLength, MinLength, NonEmpty, Trimmed};
use super::Refined;
pub type NonEmptyString = Refined<String, NonEmpty>;
pub type TrimmedString = Refined<String, Trimmed>;
pub type NonEmptyTrimmedString = Refined<String, And<NonEmpty, Trimmed>>;
pub type PositiveI8 = Refined<i8, Positive>;
pub type PositiveI16 = Refined<i16, Positive>;
pub type PositiveI32 = Refined<i32, Positive>;
pub type PositiveI64 = Refined<i64, Positive>;
pub type PositiveI128 = Refined<i128, Positive>;
pub type PositiveIsize = Refined<isize, Positive>;
pub type NonNegativeI8 = Refined<i8, NonNegative>;
pub type NonNegativeI16 = Refined<i16, NonNegative>;
pub type NonNegativeI32 = Refined<i32, NonNegative>;
pub type NonNegativeI64 = Refined<i64, NonNegative>;
pub type NonNegativeI128 = Refined<i128, NonNegative>;
pub type NonNegativeIsize = Refined<isize, NonNegative>;
pub type NegativeI8 = Refined<i8, Negative>;
pub type NegativeI16 = Refined<i16, Negative>;
pub type NegativeI32 = Refined<i32, Negative>;
pub type NegativeI64 = Refined<i64, Negative>;
pub type NegativeI128 = Refined<i128, Negative>;
pub type NegativeIsize = Refined<isize, Negative>;
pub type NonZeroI8 = Refined<i8, NonZero>;
pub type NonZeroI16 = Refined<i16, NonZero>;
pub type NonZeroI32 = Refined<i32, NonZero>;
pub type NonZeroI64 = Refined<i64, NonZero>;
pub type NonZeroI128 = Refined<i128, NonZero>;
pub type NonZeroIsize = Refined<isize, NonZero>;
pub type NonZeroU8 = Refined<u8, NonZero>;
pub type NonZeroU16 = Refined<u16, NonZero>;
pub type NonZeroU32 = Refined<u32, NonZero>;
pub type NonZeroU64 = Refined<u64, NonZero>;
pub type NonZeroU128 = Refined<u128, NonZero>;
pub type NonZeroUsize = Refined<usize, NonZero>;
pub type PositiveF32 = Refined<f32, Positive>;
pub type PositiveF64 = Refined<f64, Positive>;
pub type NonNegativeF32 = Refined<f32, NonNegative>;
pub type NonNegativeF64 = Refined<f64, NonNegative>;
pub type NegativeF32 = Refined<f32, Negative>;
pub type NegativeF64 = Refined<f64, Negative>;
pub type NonEmptyList<T> = Refined<Vec<T>, NonEmpty>;
pub type Percentage = Refined<i32, InRange<0, 100>>;
pub type Port = Refined<u16, InRange<1, 65535>>;
pub type BoundedString<const MAX: usize> = Refined<String, MaxLength<MAX>>;
pub type MinLengthString<const MIN: usize> = Refined<String, MinLength<MIN>>;
pub type BoundedVec<T, const MAX: usize> = Refined<Vec<T>, MaxSize<MAX>>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_string_aliases() {
assert!(NonEmptyString::new("hello".to_string()).is_ok());
assert!(NonEmptyString::new("".to_string()).is_err());
assert!(TrimmedString::new("hello".to_string()).is_ok());
assert!(TrimmedString::new(" hello ".to_string()).is_err());
assert!(NonEmptyTrimmedString::new("hello".to_string()).is_ok());
assert!(NonEmptyTrimmedString::new("".to_string()).is_err());
assert!(NonEmptyTrimmedString::new(" hello ".to_string()).is_err());
}
#[test]
fn test_positive_aliases() {
assert!(PositiveI32::new(1).is_ok());
assert!(PositiveI32::new(0).is_err());
assert!(PositiveI32::new(-1).is_err());
assert!(PositiveF64::new(0.1).is_ok());
assert!(PositiveF64::new(0.0).is_err());
}
#[test]
fn test_non_negative_aliases() {
assert!(NonNegativeI32::new(0).is_ok());
assert!(NonNegativeI32::new(1).is_ok());
assert!(NonNegativeI32::new(-1).is_err());
}
#[test]
fn test_negative_aliases() {
assert!(NegativeI32::new(-1).is_ok());
assert!(NegativeI32::new(0).is_err());
assert!(NegativeI32::new(1).is_err());
}
#[test]
fn test_non_zero_aliases() {
assert!(NonZeroI32::new(1).is_ok());
assert!(NonZeroI32::new(-1).is_ok());
assert!(NonZeroI32::new(0).is_err());
assert!(NonZeroU32::new(1).is_ok());
assert!(NonZeroU32::new(0).is_err());
}
#[test]
fn test_collection_aliases() {
assert!(NonEmptyList::<i32>::new(vec![1]).is_ok());
assert!(NonEmptyList::<i32>::new(vec![]).is_err());
}
#[test]
fn test_domain_aliases() {
assert!(Percentage::new(0).is_ok());
assert!(Percentage::new(100).is_ok());
assert!(Percentage::new(50).is_ok());
assert!(Percentage::new(-1).is_err());
assert!(Percentage::new(101).is_err());
assert!(Port::new(80).is_ok());
assert!(Port::new(443).is_ok());
assert!(Port::new(1).is_ok());
assert!(Port::new(65535).is_ok());
assert!(Port::new(0).is_err());
}
#[test]
fn test_bounded_string() {
type ShortString = BoundedString<10>;
assert!(ShortString::new("hello".to_string()).is_ok());
assert!(ShortString::new("this is too long".to_string()).is_err());
}
#[test]
fn test_bounded_vec() {
type SmallVec = BoundedVec<i32, 3>;
assert!(SmallVec::new(vec![1, 2, 3]).is_ok());
assert!(SmallVec::new(vec![1, 2, 3, 4]).is_err());
}
}