macro_rules! newtype_index {
($v:vis struct $name:ident { .. }) => { ... };
($v:vis struct $name:ident { $($tokens:tt)+ }) => { ... };
(@derives [$($derives:ident,)*]
@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]) => { ... };
(@handle_debug
@derives [$($_derives:ident,)*]
@type [$type:ident]
@debug_format [custom]) => { ... };
(@handle_debug
@derives []
@type [$type:ident]
@debug_format [$debug_format:tt]) => { ... };
(@handle_debug
@derives [Debug, $($derives:ident,)*]
@type [$type:ident]
@debug_format [$debug_format:tt]) => { ... };
(@handle_debug
@derives [$_derive:ident, $($derives:ident,)*]
@type [$type:ident]
@debug_format [$debug_format:tt]) => { ... };
(@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]
derive [$($derives:ident),*]
$($tokens:tt)*) => { ... };
(@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]
derive [$($derives:ident,)+]
ENCODABLE = custom
$($tokens:tt)*) => { ... };
(@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]
derive [$($derives:ident,)+]
$($tokens:tt)*) => { ... };
(@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]
ENCODABLE = custom
$($tokens:tt)*) => { ... };
(@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]
$($tokens:tt)*) => { ... };
(@decodable $type:ident) => { ... };
(@derives [$($derives:ident,)*]
@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]
$name:ident = $constant:expr) => { ... };
(@derives [$($derives:ident,)*]
@type [$type:ident]
@max [$_max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]
$(#[doc = $doc:expr])*
const $name:ident = $constant:expr) => { ... };
(@derives [$($derives:ident,)*]
@type [$type:ident]
@max [$_max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]
MAX = $max:expr,
$($tokens:tt)*) => { ... };
(@derives [$($derives:ident,)*]
@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$_debug_format:tt]
DEBUG_FORMAT = $debug_format:tt,
$($tokens:tt)*) => { ... };
(@derives [$($derives:ident,)*]
@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]
$(#[doc = $doc:expr])*
const $name:ident = $constant:expr,
$($tokens:tt)*) => { ... };
}
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 do
S::from(v)
with a usize
or u32
. And you can convert back
to an integer with u32::from(s)
.
-
Alternatively, you can use the methods S::new(v)
and s.index()
to create/return a value.
Internally, the index uses a u32, so the index must not exceed
u32::MAX
. You can also customize things like the Debug
impl,
what traits are derived, and so forth via the macro.