Skip to content

Instantly share code, notes, and snippets.

View soulsource's full-sized avatar

Andreas Grois soulsource

View GitHub Profile
@soulsource
soulsource / enum_map.rs
Last active November 6, 2023 21:26
Draft: tiny macro-by-example alternative to enum_map. Not as fast, but way simpler. Enum needs Eq and Sequence from enum_iterator.
use enum_iterator::Sequence;
macro_rules! enum_map {
($vis:vis $n:ident, $e:ty, $v:ty) => {
$vis struct $n {
elements : [$v; <$e>::CARDINALITY],
}
impl $n{
$vis fn new<F>(initializer : F) -> Self where F : Fn(&$e)->$v {
Self {