Skip to main content

Refining

Trait Refining 

Source
pub trait Refining: Deref<Target = Self::Value> + Sealed {
    type Value: ?Sized;
    type Predicate: Predicate<Self::Value> + ?Sized;
    type Context: TypeStr + ?Sized;

    // Required methods
    unsafe fn unchecked_ref(value: &Self::Value) -> &Self;
    unsafe fn unchecked(value: Self::Value) -> Self
       where Self::Value: Sized;
    fn get_ref(&self) -> &Self::Value;
    fn get(self) -> Self::Value
       where Self::Value: Sized;
    fn checked_ref(value: &Self::Value) -> RecoverableRefinementRef<'_, Self>;
    fn checked(value: Self::Value) -> RecoverableRefinement<Self>
       where Self::Value: Sized,
             Self: Sized;

    // Provided method
    fn is_fine(value: &Self::Value) -> bool { ... }
}
Expand description

Refinement methods.

This sealed trait is used for generics over Refinement<T, P, C>.

Required Associated Types§

Source

type Value: ?Sized

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

Source

type Predicate: Predicate<Self::Value> + ?Sized

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

Source

type Context: TypeStr + ?Sized

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

Required Methods§

Source

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

Constructs Self from Self::Value by reference without checking.

§Safety

This method should only be called for references that satisfy Self::Predicate.

Alternatively, this can be checked using the is_fine method.

Source

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

Constructs Self from Self::Value without checking.

§Safety

This method should only be called for values that satisfy Self::Predicate.

Alternatively, this can be checked using the is_fine method.

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.

§Errors

Returns Error<Self::Value, Self::Predicate, Self::Context> reference in case the reference does not satisfy the predicate.

Source

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

Constructs Self from Self::Value.

§Errors

Returns Error<Self::Value, Self::Predicate, Self::Context> in case the value does not satisfy the predicate.

Provided Methods§

Source

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

Checks whether the given Self::Value satisfies Self::Predicate.

This is the same as calling Self::Predicate::check on the value.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

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