const_type_layout

Macro discriminant

Source
macro_rules! discriminant {
    ($x:expr) => { ... };
}
Expand description

Helper macro to construct a Discriminant from its constant value.

The discriminant! macro is invoked with the constant expression value of the discriminant, e.g.

// unsigned literal with inferred type
const D1: Discriminant = discriminant!(4);

// signed literal with inferred type
const D2: Discriminant = discriminant!(-2);

// unsigned literal with explicit type
const D3: Discriminant = discriminant!(2_u8);

// signed literal with explicit type
const D4: Discriminant = discriminant!(-4_i128);

// constant expression with inferred type
const D5: Discriminant = discriminant!(-4 + 7);

// constant value
const VALUE: isize = 42;
const D6: Discriminant = discriminant!(VALUE);