Macro constmuck::infer[][src]

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

For constructing types that implement Infer, this includes Is* types.

This is best used when the constructed type can be inferred.

The type argument ($ty) is optional, inferred when not passed.

Alternatives

constmuck types have their own macros for constructing them, which are more concise with explicit type arguments, and help type inference.

These are the macros:

Example

Basic

use constmuck::{infer, wrapper};

use std::num::Wrapping as W;

const FOO: &[W<u8>] = wrapper::wrap_slice(&[3, 2, 1, 0], infer!());
assert_eq!(FOO, [W(3), W(2), W(1), W(0)]);

let bar = wrapper::peel_slice::<W<u8>, u8>(FOO, infer!());
assert_eq!(bar, [3, 2, 1, 0]);

Tuple

infer can contruct tuples of types that implement Infer.

use constmuck::infer;
use constmuck::{IsPod, IsTW, IsTransparentWrapper};

use std::num::Wrapping;

const fn requires_2_bounds<O, I>(_bounds: (IsPod<I>, IsTransparentWrapper<O, I>)) {}

requires_2_bounds::<Wrapping<u32>, u32>(infer!());

// the same as the above call
requires_2_bounds(infer!((IsPod<u32>, IsTransparentWrapper<Wrapping<u32>, u32>)));

// using more specific macros
requires_2_bounds((IsPod!(u32), IsTW!(Wrapping<u32>, u32)));