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
//! Proc-macro implementation for [`numbered`](https://docs.rs/numbered).
//!
//! Depend on the `numbered` crate, not this one. This crate is the host
//! proc-macro; generated items use `core` so the runtime can be `no_std`.
use TokenStream;
/// Derive stable integer numbers for a unit-like enum.
///
/// # Container attribute
///
/// ```ignore
/// #[derive(Numbered)]
/// #[numbered(u8, start = 0, crate = ::numbered)]
/// enum Kind { Process }
/// ```
///
/// - A repr type (required): `u8`, `u16`, `u32`, `u64`, `usize`, `i8`,
/// `i16`, `i32`, `i64`, or `isize`. First positional, or `repr = u8`.
/// - `start = N`: first auto-assigned number when no discriminant / `n` is
/// set. Default: `0`.
/// - `crate = ::path`: crate path emitted in generated code. Default:
/// `::numbered`. Set this when you re-export numbered from another crate.
///
/// # Variant attribute
///
/// ```ignore
/// #[numbered(n = 10)]
/// Network,
/// ```
///
/// Pins that variant to an explicit integer. A native `= 10` discriminant
/// does the same. If both are present they must agree.
///
/// # Generated items
///
/// - `const fn number(self) -> <repr>`
/// - `const fn as_u8(self) -> <repr>` (name follows the repr)
/// - `const fn from_number(n: <repr>) -> Result<Self, FromNumberError<repr>>`
/// - `from_u8` alias matching the repr
/// - `numbered::Variants` (non-generic enums): `VARIANTS` / `NUMBERS`
/// - `From<Self> for <repr>`, `TryFrom<repr> for Self`
/// - `PartialEq<repr>` both ways
/// - `Serialize` / `Deserialize` (feature `serde`)
///
/// See the [`numbered`](https://docs.rs/numbered) crate docs for assignment
/// rules, features, and `no_std`.