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>
impl<T: ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> Refinement<T, P, C>
Sourcepub const unsafe fn unchecked_ref(value: &T) -> &Self
pub const unsafe fn unchecked_ref(value: &T) -> &Self
Sourcepub fn get_ref(&self) -> &T
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.
Sourcepub const fn get_ref_no_assert(&self) -> &T
pub const fn get_ref_no_assert(&self) -> &T
Returns the contained value.
Sourcepub fn is_fine(value: &T) -> bool
pub fn is_fine(value: &T) -> bool
Checks whether the provided value satisfies P.
This is the same as calling P::check on it.
Sourcepub fn checked_ref(value: &T) -> RecoverableRef<'_, Self, P, C, T>
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>
impl<T, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> Refinement<T, P, C>
Sourcepub fn get(self) -> T
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.
Sourcepub fn get_no_assert(self) -> T
pub fn get_no_assert(self) -> T
Returns the contained value.
Sourcepub fn checked(value: T) -> Recoverable<Self, P, C, T>
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>
impl<T: ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> AsRef<T> for Refinement<T, P, C>
Source§impl<T: Debug + ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> Debug for Refinement<T, P, C>
impl<T: Debug + ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> Debug for Refinement<T, P, C>
Source§impl<T: Display + ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> Display for Refinement<T, P, C>
impl<T: Display + ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> Display for Refinement<T, P, C>
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>
impl<T: Hash + ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> Hash for Refinement<T, P, C>
Source§impl<T: Ord + ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> Ord for Refinement<T, P, C>
impl<T: Ord + ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> Ord for Refinement<T, P, C>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T: PartialEq + ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> PartialEq for Refinement<T, P, C>
impl<T: PartialEq + ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> PartialEq for Refinement<T, P, C>
Source§impl<T: PartialOrd + ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> PartialOrd for Refinement<T, P, C>
impl<T: PartialOrd + ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> PartialOrd for Refinement<T, P, C>
Source§impl<T: ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> Refining for Refinement<T, P, C>
impl<T: ?Sized, P: Predicate<T> + ?Sized, C: TypeStr + ?Sized> Refining for Refinement<T, P, C>
Source§type Value = T
type Value = T
T in Refinement<T, P, C>).Source§type Predicate = P
type Predicate = P
P in Refinement<T, P, C>).Source§type Context = C
type Context = C
C in Refinement<T, P, C>).Source§unsafe fn unchecked_ref(value: &Self::Value) -> &Self
unsafe fn unchecked_ref(value: &Self::Value) -> &Self
Source§fn checked_ref(value: &Self::Value) -> RecoverableRefinementRef<'_, Self>
fn checked_ref(value: &Self::Value) -> RecoverableRefinementRef<'_, Self>
Source§fn checked(value: Self::Value) -> RecoverableRefinement<Self>
fn checked(value: Self::Value) -> RecoverableRefinement<Self>
Auto Trait Implementations§
impl<T, P, C> Freeze for Refinement<T, P, C>
impl<T, P, C> RefUnwindSafe for Refinement<T, P, C>
impl<T, P, C> Send for Refinement<T, P, C>
impl<T, P, C> Sync for Refinement<T, P, C>
impl<T, P, C> Unpin for Refinement<T, P, C>
impl<T, P, C> UnsafeUnpin for Refinement<T, P, C>
impl<T, P, C> UnwindSafe for Refinement<T, P, C>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Refine for Twhere
T: ?Sized,
impl<T> Refine for Twhere
T: ?Sized,
Source§fn refine_ref<R: Refining<Value = Self> + ?Sized>(
&self,
) -> RecoverableRefinementRef<'_, R>
fn refine_ref<R: Refining<Value = Self> + ?Sized>( &self, ) -> RecoverableRefinementRef<'_, R>
R by reference. Read more