typed_index_derive
Custom derive to easily create newtype index types.
A frequent pattern in Rust is to store objects in a vector and use integer indexes
as handlers to them. While using usize
works, it could become confusing if there
are several flavors of indexes. To make the meaning of each index clear the newtype
wrappers like FooIdx(usize)
are useful, but require a fair amount of boilerplate.
This crate derives the boilerplate for you:
extern crate typed_index_derive;
;
// index into `&[Spam]`
; // could be `u32` instead of `usize`