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 methods
    unsafe fn unchecked_default() -> Self
       where Self::Value: Default,
             Self: Sized { ... }
    fn is_fine(value: &Self::Value) -> bool { ... }
    fn checked_default() -> RecoverableRefinement<Self>
       where Self::Value: Default,
             Self: Sized { ... }
}
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

unsafe fn unchecked_default() -> Self
where Self::Value: Default, Self: Sized,

Constructs Self from default Self::Value without checking.

§Safety

This method should only be called if the default value satisfies Self::Predicate.

Alternatively, this can be checked using the is_fine method.

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.

Source

fn checked_default() -> RecoverableRefinement<Self>
where Self::Value: Default, Self: Sized,

Constructs Self from default Self::Value.

§Errors

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

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>