1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//! 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
pub use *;
/// 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.
pub use 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 {}
/// ```
pub use IntegerIdCounter;
/// Implements [`IntegerIdContiguous`] for a newtype struct.
///
/// This is implicitly generated by `derive(IntegerIdCounter)`.
pub use 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:?}");
/// ```
pub use EnumId;