Skip to main content

Refinement

Struct Refinement 

Source
pub struct Refinement<T: ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized = NoContext> { /* private fields */ }
Expand description

Represents refinement types.

Implementations§

Source§

impl<T: ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> Refinement<T, P, C>

Source

pub const unsafe fn unchecked_ref(value: &T) -> &Self

Constructs Self by reference without checking.

§Safety

This method should only be called for references that satisfy P, which can be checked via is_fine.

Source

pub fn get_ref(&self) -> &T

Returns the contained value reference.

If the unsafe-assert feature is enabled, assert_unchecked is called on the reference before returning.

The get_ref_no_assert method is provided in case the assertion is explicitly not needed.

Source

pub const fn get_ref_no_assert(&self) -> &T

Returns the contained value.

Source

pub fn is_fine(value: &T) -> bool

Checks whether the provided value satisfies P.

This is the same as calling P::check on it.

Source

pub fn checked_ref(value: &T) -> RecoverableRef<'_, Self, P, C, T>

Constructs Self by reference.

§Errors

Returns Error<T, P, C> in case the reference does not satisfy P.

Source§

impl<T, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> Refinement<T, P, C>

Source

pub const unsafe fn unchecked(value: T) -> Self

Constructs Self without checking the value.

§Safety

This method should only be called for values that satisfy the predicate P, which can be checked using is_fine.

Source

pub fn get(self) -> T

Returns the contained value.

If the unsafe-assert feature is enabled, assert_unchecked is called on the reference before returning the value.

The get_no_assert method is provided in case the assertion is explicitly not needed.

Source

pub fn get_no_assert(self) -> T

Returns the contained value.

Source

pub fn checked(value: T) -> Recoverable<Self, P, C, T>

Constructs Self from the given value.

§Errors

Returns Error<T, P, C> in case the value does not satisfy P.

Trait Implementations§

Source§

impl<T: ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> AsRef<T> for Refinement<T, P, C>

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: Debug + ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> Debug for Refinement<T, P, C>

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> Deref for Refinement<T, P, C>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T: Display + ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> Display for Refinement<T, P, C>

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Eq + ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> Eq for Refinement<T, P, C>

Source§

impl<T: Hash + ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> Hash for Refinement<T, P, C>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: Ord + ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> Ord for Refinement<T, P, C>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq + ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> PartialEq for Refinement<T, P, C>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd + ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> PartialOrd for Refinement<T, P, C>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> Refining for Refinement<T, P, C>

Source§

type Value = T

The refinement value (T in Refinement<T, P, C>).
Source§

type Predicate = P

The refinement predicate (P in Refinement<T, P, C>).
Source§

type Context = C

The refinement context (C in Refinement<T, P, C>).
Source§

unsafe fn unchecked_ref(value: &Self::Value) -> &Self

Constructs Self from Self::Value by reference without checking. Read more
Source§

unsafe fn unchecked(value: Self::Value) -> Self
where Self::Value: Sized,

Constructs Self from Self::Value without checking. Read more
Source§

fn is_fine(value: &Self::Value) -> bool

Checks whether the given Self::Value satisfies Self::Predicate. Read more
Source§

fn get_ref(&self) -> &Self::Value

Returns the contained value reference.
Source§

fn get(self) -> Self::Value
where Self::Value: Sized,

Returns the contained value.
Source§

fn checked_ref(value: &Self::Value) -> RecoverableRefinementRef<'_, Self>

Constructs Self from Self::Value by reference. Read more
Source§

fn checked(value: Self::Value) -> RecoverableRefinement<Self>
where Self::Value: Sized,

Constructs Self from Self::Value. Read more

Auto Trait Implementations§

§

impl<T, P, C> Freeze for Refinement<T, P, C>
where T: Freeze + ?Sized, P: ?Sized, C: ?Sized,

§

impl<T, P, C> RefUnwindSafe for Refinement<T, P, C>

§

impl<T, P, C> Send for Refinement<T, P, C>
where T: Send + ?Sized, P: Send + ?Sized, C: Send + ?Sized,

§

impl<T, P, C> Sync for Refinement<T, P, C>
where T: Sync + ?Sized, P: Sync + ?Sized, C: Sync + ?Sized,

§

impl<T, P, C> Unpin for Refinement<T, P, C>
where T: Unpin + ?Sized, P: Unpin + ?Sized, C: Unpin + ?Sized,

§

impl<T, P, C> UnsafeUnpin for Refinement<T, P, C>
where T: UnsafeUnpin + ?Sized, P: ?Sized, C: ?Sized,

§

impl<T, P, C> UnwindSafe for Refinement<T, P, C>
where T: UnwindSafe + ?Sized, P: UnwindSafe + ?Sized, C: UnwindSafe + ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Check for T
where T: ?Sized,

Source§

fn satisfies<P: Predicate<Self> + ?Sized>(&self) -> bool

Checks whether the Self value satisfies the given predicate. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Refine for T
where T: ?Sized,

Source§

fn refine_ref<R: Refining<Value = Self> + ?Sized>( &self, ) -> RecoverableRefinementRef<'_, R>

Refines the given value with R by reference. Read more
Source§

fn refine<R: Refining<Value = Self>>(self) -> RecoverableRefinement<R>
where Self: Sized,

Refines the given value with R. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.