Macro rustc_index_macros::newtype_index
source ยท newtype_index!() { /* proc-macro */ }
Expand description
Creates a struct type S
that can be used as an index with
IndexVec
and so on.
There are two ways of interacting with these indices:
-
The
From
impls are the preferred way. So you can doS::from(v)
with ausize
oru32
. And you can convert back to an integer withu32::from(s)
. -
Alternatively, you can use the methods
S::new(v)
ands.index()
to create/return a value.
Internally, the index uses a u32, so the index must not exceed
u32::MAX
.
The impls provided by default are Clone, Copy, PartialEq, Eq, and Hash.
Accepted attributes for customization:
#[derive(HashStable_Generic)]
/#[derive(HashStable)]
: derivesHashStable
, as normal.#[encodable]
: derivesEncodable
/Decodable
.#[orderable]
: derivesPartialOrd
/Ord
, plus step-related methods.#[debug_format = "Foo({})"]
: derivesDebug
with particular output.#[max = 0xFFFF_FFFD]
: specifies the max value, which allows niche optimizations. The default max value is 0xFFFF_FF00.#[gate_rustc_only]
: makes parts of the generated code nightly-only.