intid 0.3.5

Defines the IntegerId trait
Documentation
//! Defines the [`IntegerId`] trait, for types that can be identified by an integer value.
//!
//! This crate simply re-exports all types from the [`intid_core`] crate.
//! This reduces compile times by allowing crates to avoid proc macros.
//! It is inspired by the separation between `serde_core` and `serde` introduced in [serde-rs/serde#2608].
//!
//! Note that many of the use-cases of a `derive(...)` macro can be achieved just as well (or better)
//! using the [`intid::define_newtype_id`](crate::define_newtype_id) declarative macro.
//!
//! [serde-rs/serde#2608]: https://github.com/serde-rs/serde/pull/2608
#![no_std]

pub use intid_core::*;

/// Implements [`IntegerId`] for a newtype struct or C-like enum.
///
///
/// Note that many of the use-cases of a `derive(...)` macro can be achieved just as well (or better)
/// using the [`intid::define_newtype_id!`](crate::define_newtype_id) declarative macro.
/// In particular, that macro also derives `Ord + Eq + Hash`,
/// saving some boilerplate.
#[cfg(feature = "derive")]
pub use intid_derive::IntegerId;

/// Implements [`IntegerIdCounter`] for a newtype struct.
///
/// ```rust
/// use intid::{IntegerId, IntegerIdCounter};
/// #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
/// #[derive(IntegerIdCounter, IntegerId)]
/// struct Example(u32);
/// fn print_counter<T: IntegerIdCounter>() -> String {
///     format!("Starting at {:?}", T::START)
/// }
/// assert_eq!(
///     print_counter::<Example>(),
///     "Starting at Example(0)"
/// );
/// ```
///
/// This will automatically derive `IntegerIdContiguous` trait as well,
/// since that trait is necessary to implement `IntegerIdCounter`.
/// Skip deriving the contiguous trait by using the attribute `#[intid(counter(skip_contiguous))]`:
/// ```rust
/// use intid::{IntegerIdCounter, IntegerId};
/// #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
/// #[derive(IntegerId, IntegerIdCounter)]
/// #[intid(counter(skip_contiguous))]
/// struct Explicit(u32);
/// impl intid::IntegerIdContiguous for Explicit {}
/// ```
#[cfg(feature = "derive")]
pub use intid_derive::IntegerIdCounter;

/// Implements [`IntegerIdContiguous`] for a newtype struct.
///
/// This is implicitly generated by `derive(IntegerIdCounter)`.
#[cfg(feature = "derive")]
pub use intid_derive::IntegerIdContiguous;

/// Implements [`EnumId`] for a C-like enum,
/// enabling use of the `EnumMap` and `EnumSet` collections.
///
/// This requires that the type also implement the [`IntegerId`] trait,
/// usually requiring an additional `derive(intid::IntegerId)`.
///
/// # Example
/// ```
/// #[derive(Copy, Clone, Debug, Eq, PartialEq)]
/// #[derive(intid::IntegerId, intid::EnumId)]
/// enum City {
///     NewYork,
///     Boston,
///     London,
/// }
///
/// let countries = idmap::enum_map! {
///     City::NewYork => "United States",
///     City::London => "England",
/// };
/// println!("{countries:?}");
/// ```
#[cfg(feature = "derive")]
pub use intid_derive::EnumId;