AcceptUpperBound

Trait AcceptUpperBound 

Source
pub trait AcceptUpperBound {
    type Output;
    type Eval<const UPPER: usize>: Const<Type = Self::Output>;

    const DESIRED_GENERIC: usize;
}
Expand description

Allows implementing a callback pattern that accepts an upper bound for a desired generic const parameter.

The trait works by allowing implementors to specify, for each upper bound, a value that is computed from that upper bound. This value is represented as a generic associated type with bound Const, as this is currently the only way to implement a const item with generics in a trait.

When passed to eval_with_upper_bound, Eval::<UPPER>::VALUE will be evaluated with a parameter UPPER that satisfies DESIRED_GENERIC <= UPPER < 2 * DESIRED_GENERIC.

Required Associated Constants§

Source

const DESIRED_GENERIC: usize

The desired value and lower bound that the implementor wants to be passed to Self::Eval.

Required Associated Types§

Source

type Output

The output type of the evaluation.

Source

type Eval<const UPPER: usize>: Const<Type = Self::Output>

Evals the constant by mapping a generic parameter that is at least the desired value to the output value. const_value::<Eval<UPPER>>() should be indistinguishable for all possible generic parameters passed to this.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§