Macro constmuck::type_size[][src]

macro_rules! type_size {
    ($ty : ty) => { ... };
}
Expand description

Constructs a TypeSize.

This implicitly constructs the bounds field of a TypeSize with Infer::INFER.

Example

Making a oned function

use constmuck::{ImplsPod, TypeSize};
use constmuck::{infer, type_size};

pub const fn oned<T, const SIZE: usize>(bound: TypeSize<ImplsPod<T>, T, SIZE>) -> T {
    constmuck::cast::<[u8; SIZE], T>(
        [1; SIZE],
        // `infer!()` here constructs an `ImplsPod<[u8; SIZE]>`
        //
        // `bound.into_bounds()` extracts the `bounds` field, which is `ImplsPod<T>` here.
        (infer!(), bound.into_bounds())
    )
}

const U64: u64 = oned(type_size!(u64));
const ONES: [u8; 5] = oned(type_size!([u8; 5]));

assert_eq!(U64, 0x01_01_01_01_01_01_01_01);
assert_eq!(ONES, [1, 1, 1, 1, 1]);