[−][src]Struct refinement::Refinement
A Refinement
type ensures all values of a particular type satisfy a Predicate
.
Use as_inner
/to_inner
to access the
underlying value or into_inner
to unwrap the value.
Refinement
also implements many common standard library traits if the underlying
value also implements them.
Examples
use refinement::{Predicate, Refinement}; struct LessThanTen; impl Predicate<i32> for LessThanTen { fn test(x: &i32) -> bool { *x < 10 } } type LessThanTenInt = Refinement<i32, LessThanTen>; let x = LessThanTenInt::new(5); assert!(x.is_some()); let y = LessThanTenInt::new(11); assert!(y.is_none());
Implementations
impl<T, P> Refinement<T, P> where
P: Predicate<T>,
[src]
P: Predicate<T>,
pub fn new(x: T) -> Option<Self>
[src]
Create a refined value from the underlying type T
.
Returns x
under the refinement type if x
satisfies P
, otherwise returns None
.
Examples
use refinement::{Predicate, Refinement}; struct NonEmpty; impl Predicate<String> for NonEmpty { fn test(x: &String) -> bool { !x.is_empty() } } type NonEmptyString = Refinement<String, NonEmpty>; let s1 = NonEmptyString::new(String::from("Hello")); assert!(s1.is_some()); let s2 = NonEmptyString::new(String::from("")); assert!(s2.is_none());
pub fn into_inner(self) -> T
[src]
Unwrap the underlying value, consuming self
.
Examples
use refinement::{Predicate, Refinement}; struct ThreeDigit; impl Predicate<String> for ThreeDigit { fn test(x: &String) -> bool { x.chars().count() == 3 && x.chars().filter(|c| c.is_ascii_digit()).count() == 3 } } type ThreeDigitString = Refinement<String, ThreeDigit>; let s = ThreeDigitString::new(String::from("123")); assert_eq!(String::from("123"), s.unwrap().into_inner());
impl<T, P> Refinement<T, P> where
T: Clone,
P: Predicate<T>,
[src]
T: Clone,
P: Predicate<T>,
pub fn to_inner(&self) -> T
[src]
Retrieve the underlying value without consuming self
.
Examples
use refinement::{Predicate, Refinement}; struct ThreeDigit; impl Predicate<String> for ThreeDigit { fn test(x: &String) -> bool { x.chars().count() == 3 && x.chars().filter(|c| c.is_ascii_digit()).count() == 3 } } type ThreeDigitString = Refinement<String, ThreeDigit>; let s = ThreeDigitString::new(String::from("123")); assert_eq!(String::from("123"), s.unwrap().to_inner());
impl<T, P> Refinement<T, P> where
T: Copy,
P: Predicate<T>,
[src]
T: Copy,
P: Predicate<T>,
pub fn as_inner(&self) -> T
[src]
Retrieve the underlying value for Copy
types without consuming self
.
Examples
use refinement::{Predicate, Refinement}; struct LessThanTen; impl Predicate<i32> for LessThanTen { fn test(x: &i32) -> bool { *x < 10 } } type LessThanTenInt = Refinement<i32, LessThanTen>; let x = LessThanTenInt::new(5); assert_eq!(5, x.unwrap().as_inner());
Trait Implementations
impl<T, P> Add<Refinement<T, P>> for Refinement<T, P> where
T: Add<Output = T>,
P: Predicate<T>,
[src]
T: Add<Output = T>,
P: Predicate<T>,
type Output = Option<Self>
The resulting type after applying the +
operator.
pub fn add(self, rhs: Self) -> Self::Output
[src]
impl<T, P> Add<T> for Refinement<T, P> where
T: Add<Output = T>,
P: Predicate<T>,
[src]
T: Add<Output = T>,
P: Predicate<T>,
type Output = Option<Self>
The resulting type after applying the +
operator.
pub fn add(self, rhs: T) -> Self::Output
[src]
impl<T, P> AsRef<T> for Refinement<T, P> where
P: Predicate<T>,
[src]
P: Predicate<T>,
impl<T, P> BitAnd<Refinement<T, P>> for Refinement<T, P> where
T: BitAnd<Output = T>,
P: Predicate<T>,
[src]
T: BitAnd<Output = T>,
P: Predicate<T>,
type Output = Option<Self>
The resulting type after applying the &
operator.
pub fn bitand(self, rhs: Self) -> Self::Output
[src]
impl<T, P> BitAnd<T> for Refinement<T, P> where
T: BitAnd<Output = T>,
P: Predicate<T>,
[src]
T: BitAnd<Output = T>,
P: Predicate<T>,
type Output = Option<Self>
The resulting type after applying the &
operator.
pub fn bitand(self, rhs: T) -> Self::Output
[src]
impl<T, P> BitOr<Refinement<T, P>> for Refinement<T, P> where
T: BitOr<Output = T>,
P: Predicate<T>,
[src]
T: BitOr<Output = T>,
P: Predicate<T>,
type Output = Option<Self>
The resulting type after applying the |
operator.
pub fn bitor(self, rhs: Self) -> Self::Output
[src]
impl<T, P> BitOr<T> for Refinement<T, P> where
T: BitOr<Output = T>,
P: Predicate<T>,
[src]
T: BitOr<Output = T>,
P: Predicate<T>,
type Output = Option<Self>
The resulting type after applying the |
operator.
pub fn bitor(self, rhs: T) -> Self::Output
[src]
impl<T, P> BitXor<Refinement<T, P>> for Refinement<T, P> where
T: BitXor<Output = T>,
P: Predicate<T>,
[src]
T: BitXor<Output = T>,
P: Predicate<T>,
type Output = Option<Self>
The resulting type after applying the ^
operator.
pub fn bitxor(self, rhs: Self) -> Self::Output
[src]
impl<T, P> BitXor<T> for Refinement<T, P> where
T: BitXor<Output = T>,
P: Predicate<T>,
[src]
T: BitXor<Output = T>,
P: Predicate<T>,
type Output = Option<Self>
The resulting type after applying the ^
operator.
pub fn bitxor(self, rhs: T) -> Self::Output
[src]
impl<T, P> Borrow<T> for Refinement<T, P> where
P: Predicate<T>,
[src]
P: Predicate<T>,
impl<T: Clone, P: Clone> Clone for Refinement<T, P>
[src]
pub fn clone(&self) -> Refinement<T, P>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: Copy, P: Copy> Copy for Refinement<T, P>
[src]
impl<T: Debug, P: Debug> Debug for Refinement<T, P>
[src]
impl<T, P> Display for Refinement<T, P> where
T: Display,
P: Predicate<T>,
[src]
T: Display,
P: Predicate<T>,
impl<T, P> Div<Refinement<T, P>> for Refinement<T, P> where
T: Div<Output = T>,
P: Predicate<T>,
[src]
T: Div<Output = T>,
P: Predicate<T>,
type Output = Option<Self>
The resulting type after applying the /
operator.
pub fn div(self, rhs: Self) -> Self::Output
[src]
impl<T, P> Div<T> for Refinement<T, P> where
T: Div<Output = T>,
P: Predicate<T>,
[src]
T: Div<Output = T>,
P: Predicate<T>,
type Output = Option<Self>
The resulting type after applying the /
operator.
pub fn div(self, rhs: T) -> Self::Output
[src]
impl<T: Eq, P: Eq> Eq for Refinement<T, P>
[src]
impl<T: Hash, P: Hash> Hash for Refinement<T, P>
[src]
pub fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T, P, I> Index<I> for Refinement<T, P> where
T: Index<I>,
P: Predicate<T>,
[src]
T: Index<I>,
P: Predicate<T>,
type Output = T::Output
The returned type after indexing.
pub fn index(&self, index: I) -> &Self::Output
[src]
impl<T, P> Mul<Refinement<T, P>> for Refinement<T, P> where
T: Mul<Output = T>,
P: Predicate<T>,
[src]
T: Mul<Output = T>,
P: Predicate<T>,
type Output = Option<Self>
The resulting type after applying the *
operator.
pub fn mul(self, rhs: Self) -> Self::Output
[src]
impl<T, P> Mul<T> for Refinement<T, P> where
T: Mul<Output = T>,
P: Predicate<T>,
[src]
T: Mul<Output = T>,
P: Predicate<T>,
type Output = Option<Self>
The resulting type after applying the *
operator.
pub fn mul(self, rhs: T) -> Self::Output
[src]
impl<T, P> Neg for Refinement<T, P> where
T: Neg<Output = T>,
P: Predicate<T>,
[src]
T: Neg<Output = T>,
P: Predicate<T>,
type Output = Option<Self>
The resulting type after applying the -
operator.
pub fn neg(self) -> Self::Output
[src]
impl<T, P> Not for Refinement<T, P> where
T: Not<Output = T>,
P: Predicate<T>,
[src]
T: Not<Output = T>,
P: Predicate<T>,
type Output = Option<Self>
The resulting type after applying the !
operator.
pub fn not(self) -> Self::Output
[src]
impl<T: Ord, P: Ord> Ord for Refinement<T, P>
[src]
pub fn cmp(&self, other: &Refinement<T, P>) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<T: PartialEq, P: PartialEq> PartialEq<Refinement<T, P>> for Refinement<T, P>
[src]
pub fn eq(&self, other: &Refinement<T, P>) -> bool
[src]
pub fn ne(&self, other: &Refinement<T, P>) -> bool
[src]
impl<T: PartialOrd, P: PartialOrd> PartialOrd<Refinement<T, P>> for Refinement<T, P>
[src]
pub fn partial_cmp(&self, other: &Refinement<T, P>) -> Option<Ordering>
[src]
pub fn lt(&self, other: &Refinement<T, P>) -> bool
[src]
pub fn le(&self, other: &Refinement<T, P>) -> bool
[src]
pub fn gt(&self, other: &Refinement<T, P>) -> bool
[src]
pub fn ge(&self, other: &Refinement<T, P>) -> bool
[src]
impl<T, P, B> RangeBounds<B> for Refinement<T, P> where
T: RangeBounds<B>,
P: Predicate<T>,
[src]
T: RangeBounds<B>,
P: Predicate<T>,
pub fn start_bound(&self) -> Bound<&B>
[src]
pub fn end_bound(&self) -> Bound<&B>
[src]
pub fn assert_len(self, len: usize) -> Range<usize> where
Self: RangeBounds<usize>,
[src]
Self: RangeBounds<usize>,
pub fn contains<U>(&self, item: &U) -> bool where
T: PartialOrd<U>,
U: PartialOrd<T> + ?Sized,
1.35.0[src]
T: PartialOrd<U>,
U: PartialOrd<T> + ?Sized,
impl<T, P> Rem<Refinement<T, P>> for Refinement<T, P> where
T: Rem<Output = T>,
P: Predicate<T>,
[src]
T: Rem<Output = T>,
P: Predicate<T>,
type Output = Option<Self>
The resulting type after applying the %
operator.
pub fn rem(self, rhs: Self) -> Self::Output
[src]
impl<T, P> Rem<T> for Refinement<T, P> where
T: Rem<Output = T>,
P: Predicate<T>,
[src]
T: Rem<Output = T>,
P: Predicate<T>,
type Output = Option<Self>
The resulting type after applying the %
operator.
pub fn rem(self, rhs: T) -> Self::Output
[src]
impl<T, P> Shl<Refinement<T, P>> for Refinement<T, P> where
T: Shl<Output = T>,
P: Predicate<T>,
[src]
T: Shl<Output = T>,
P: Predicate<T>,
type Output = Option<Self>
The resulting type after applying the <<
operator.
pub fn shl(self, rhs: Self) -> Self::Output
[src]
impl<T, P> Shl<T> for Refinement<T, P> where
T: Shl<Output = T>,
P: Predicate<T>,
[src]
T: Shl<Output = T>,
P: Predicate<T>,
type Output = Option<Self>
The resulting type after applying the <<
operator.
pub fn shl(self, rhs: T) -> Self::Output
[src]
impl<T, P> Shr<Refinement<T, P>> for Refinement<T, P> where
T: Shr<Output = T>,
P: Predicate<T>,
[src]
T: Shr<Output = T>,
P: Predicate<T>,
type Output = Option<Self>
The resulting type after applying the >>
operator.
pub fn shr(self, rhs: Self) -> Self::Output
[src]
impl<T, P> Shr<T> for Refinement<T, P> where
T: Shr<Output = T>,
P: Predicate<T>,
[src]
T: Shr<Output = T>,
P: Predicate<T>,
type Output = Option<Self>
The resulting type after applying the >>
operator.
pub fn shr(self, rhs: T) -> Self::Output
[src]
impl<T, P> StructuralEq for Refinement<T, P>
[src]
impl<T, P> StructuralPartialEq for Refinement<T, P>
[src]
impl<T, P> Sub<Refinement<T, P>> for Refinement<T, P> where
T: Sub<Output = T>,
P: Predicate<T>,
[src]
T: Sub<Output = T>,
P: Predicate<T>,
type Output = Option<Self>
The resulting type after applying the -
operator.
pub fn sub(self, rhs: Self) -> Self::Output
[src]
impl<T, P> Sub<T> for Refinement<T, P> where
T: Sub<Output = T>,
P: Predicate<T>,
[src]
T: Sub<Output = T>,
P: Predicate<T>,
Auto Trait Implementations
impl<T, P> RefUnwindSafe for Refinement<T, P> where
P: RefUnwindSafe,
T: RefUnwindSafe,
[src]
P: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, P> Send for Refinement<T, P> where
P: Send,
T: Send,
[src]
P: Send,
T: Send,
impl<T, P> Sync for Refinement<T, P> where
P: Sync,
T: Sync,
[src]
P: Sync,
T: Sync,
impl<T, P> Unpin for Refinement<T, P> where
P: Unpin,
T: Unpin,
[src]
P: Unpin,
T: Unpin,
impl<T, P> UnwindSafe for Refinement<T, P> where
P: UnwindSafe,
T: UnwindSafe,
[src]
P: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,