//! A simple id-based arena, similar to https://github.com/fitzgen/id-arena. //! We use our own version for more compact id's and to allow inherent impls //! on Ids. use std::{ fmt, hash::{Hash, Hasher}, marker::PhantomData, }; pub struct Id { idx: u32, _ty: PhantomData T>, } impl fmt::Debug for Id { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_tuple("Id").field(&self.idx).finish() } } impl Copy for Id {} impl Clone for Id { fn clone(&self) -> Id { *self } } impl PartialEq for Id { fn eq(&self, other: &Id) -> bool { self.idx == other.idx } } impl Eq for Id {} impl Hash for Id { fn hash(&self, h: &mut H) { self.idx.hash(h); } } #[derive(Debug, PartialEq, Eq)] pub(crate) struct ArenaBehavior { _ty: PhantomData, } impl id_arena::ArenaBehavior for ArenaBehavior { type Id = Id; fn new_arena_id() -> u32 { 0 } fn new_id(_arena_id: u32, index: usize) -> Id { Id { idx: index as u32, _ty: PhantomData, } } fn index(id: Id) -> usize { id.idx as usize } fn arena_id(_id: Id) -> u32 { 0 } } pub(crate) type Arena = id_arena::Arena>;