Function constmuck::contiguous::into_integer[][src]

pub const fn into_integer<T, IntRepr>(
    value: T,
    _bounds: &IsContiguous<T, IntRepr>
) -> IntRepr
Expand description

Converts value: T into IntRepr (its integer representation).

Requires that T implements Contiguous<Int = IntRepr>

By-reference IsContiguous argument

This takes an IsContiguous by reference, to allow calling this function in a function generic over the integer representation (eg: const fn foo<T, I>(bound: &IsContiguous<T, I>, ) multiple times.

The constmuck::contiguous::from_* functions have a concrete integer representation they deal with, which means the IsContiguous type they take implements Copy, and can be passed by value multiple times.

Example

use constmuck::{Contiguous, IsContiguous, contiguous, infer};

#[repr(i8)]
#[derive(Debug, PartialEq, Copy, Clone)]
enum Order {
    FrontToBack = 10,
    BackToFront = 11,
    RightToLeft = 12,
    LeftToRight = 13,
}

unsafe impl Contiguous for Order {
   type Int = i8;

   const MIN_VALUE: i8 = 10;
   const MAX_VALUE: i8 = 13;
}


const FTB: i8 = contiguous::into_integer(Order::FrontToBack, &infer!());
assert_eq!(FTB, 10);

const BTF: i8 = contiguous::into_integer(Order::BackToFront, &IsContiguous!());
assert_eq!(BTF, 11);

const RTL: i8 = contiguous::into_integer(Order::RightToLeft, &IsContiguous!(Order));
assert_eq!(RTL, 12);

const LTR: i8 = contiguous::into_integer(Order::LeftToRight, &IsContiguous!(Order, i8));
assert_eq!(LTR, 13);