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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/// Macro that expands to a type-level representation of a field name.
///
/// This macro can be passed as the `Names` argument of
/// [`FieldType`] and [`GetFieldType`], as the name of the field.
///
/// This expands to one of these:
/// - [`TIdent`](crate::TIdent)
/// - [`Usize`](crate::Usize)
///
/// # Examples
///
/// For an example of manually implementing [`FieldType`]
/// you can [look here](crate::FieldType#manual-impl-example).
///
/// ### Querying a field's type
///
/// ```rust
/// use multiconst::{GetFieldType, field_name};
///
/// {
/// type RU = std::ops::Range<usize>;
///
/// let _: GetFieldType<RU, field_name!(start)> = 100usize;
/// let _: GetFieldType<RU, field_name!(end)> = 100usize;
/// }
///
/// {
/// type TUP = (&'static str, Option<u8>);
///
/// let _: GetFieldType<TUP, field_name!(0)> = "hello";
/// let _: GetFieldType<TUP, field_name!(1)> = Some(10u8);
/// }
///
///
/// ```
///
/// [`FieldType`]: crate::FieldType
/// [`GetFieldType`]: crate::GetFieldType
///
/// Declares type aliases for type-level representations of field names.
///
/// The aliases can be passed as the `Names` argument of
/// [`FieldType`] and [`GetFieldType`], as the name of the field.
///
/// # Examples
///
/// ### Querying a field's type
///
/// ```rust
/// use multiconst::GetFieldType;
///
/// mod names {
/// multiconst::field_name_aliases!{
/// // equivalent to `pub(super) type F0 = field_name!(0);`
/// pub(super) F0 = 0,
///
/// // equivalent to `pub(crate) type F1 = field_name!(1);`
/// pub(crate) F1 = 1,
///
/// // equivalent to `pub type start = field_name!(start);`
/// pub start,
///
/// // equivalent to `pub type End = field_name!(end);`
/// pub End = end,
/// }
/// }
///
/// {
/// type RU = std::ops::Range<char>;
///
/// let _: GetFieldType<RU, names::start> = 'a';
/// let _: GetFieldType<RU, names::End> = 'b';
/// }
///
/// {
/// type TUP = (&'static str, Option<u8>);
///
/// let _: GetFieldType<TUP, names::F0> = "hello";
/// let _: GetFieldType<TUP, names::F1> = Some(10u8);
/// }
///
/// ```
///
///
/// [`FieldType`]: crate::FieldType
/// [`GetFieldType`]: crate::GetFieldType
///