Expand description
A crate for enumerable types.
This crate provides the Linearize trait which defines a bijection between a type and an interval of the natural numbers.
Given such a bijection, many useful things become possible. For example, this crate defines the types StaticMap and StaticCopyMap which provide high-performance, non-allocating mappings from linearizable types to arbitrary values.
#[derive(Linearize)]
enum ColorFormat {
R,
Rgb {
alpha: bool,
},
}
let mut channels = StaticMap::default();
channels[ColorFormat::R] = 1;
channels[ColorFormat::Rgb { alpha: false }] = 3;
channels[ColorFormat::Rgb { alpha: true }] = 4;
assert_eq!(channels[ColorFormat::Rgb { alpha: false }], 3);
These maps can be constructed conveniently with the static_map macro:
let channels = static_map! {
ColorFormat::R => 1,
ColorFormat::Rgb { alpha } => 3 + alpha as u32,
};
assert_eq!(channels[ColorFormat::Rgb { alpha: false }], 3);
§Features
The following features are enabled by default:
std
This crate provides the following features:
alloc
: Adds a dependency on thealloc
crate. This implements additional traits for the map types.std
: Adds a dependency on thestd
crate.derive
: Provides the Linearize derive macro.serde-1
: ImplementsSerialize
andDeserialize
from serde 1.x for the map types.arbitrary-1
: ImplementsArbitrary
from arbitrary 1.x for the map types.bytemuck-1
: ImplementsNoUninit
,Zeroable
, andAnyBitPattern
from bytemuck 1.x for the map types.rand-0_8
: Implements various distributions from rand 0.8.x for the map types.rand-0_9
: Implements various distributions from rand 0.9.x for the map types.
Modules§
- iter
- All iterators exposed by this crate.
Macros§
- static_
copy_ map - Macro to create a StaticCopyMap.
- static_
map - Macro to create a StaticMap.
Structs§
- Linearized
- Pre-computed output of Linearize::linearize.
- Static
Copy Map - A copyable, array-backed map with complex keys.
- Static
Map - An array-backed map with complex keys.
Traits§
- Linearize
- Types whose values can be enumerated.
- Linearize
Ext - Extension trait for types implementing Linearize.