#![crate_name = "tlid"] use core::{ clone::Clone, fmt::Debug, ops::{Add, AddAssign, Sub}, }; mod allocator; mod behavior; mod pool; pub use allocator::AllocError; pub use behavior::{Behavior, Checked, CheckedError, UnChecked, Wrapping}; pub use pool::Pool; #[cfg(feature = "num-traits")] extern crate num_traits; #[cfg(feature = "serde")] extern crate serde; /// trait that is used to describe all types that can be used as an ID /// types like usize, u64, i64, ... are supported by default /// /// - Ord: is needed for keeping a BTreeMap over free ranges /// - Copy: as IDs should be small enough to be copied everywhere /// - Add/Sub/AddAssign: for logic to increase and check generated IDs /// - Default: to count the number of ID's in a pool /// - Debug: to be used in Error Types and printed /// - From to convert 1 into the respective ID type pub trait IdAble: Ord + Copy + Add + Sub + AddAssign + Default + Debug + From { fn inc(&mut self); fn inc_by(&mut self, other: Self); } impl + Sub + AddAssign + Default + Debug + From> IdAble for X { fn inc(&mut self) { *self += X::from(1); } fn inc_by(&mut self, other: Self) { *self += other; } }