1
1
macro_rules! impl_kind {
2
2
(
3
3
$( #[ $outer: meta] ) *
4
- pub enum $name : ident {
4
+ pub enum $Kind : ident {
5
5
$(
6
6
$( #[ $inner: ident $( $args: tt) * ] ) *
7
- $variant : ident { bit: $bit : expr, align: $align : expr, size: $size : expr } ,
7
+ $Variant : ident { bit: $BIT : expr, align: $ALIGN : expr, size: $SIZE : expr } ,
8
8
) +
9
9
}
10
10
) => {
11
11
$( #[ $outer] ) *
12
- pub enum $name {
12
+ pub enum $Kind {
13
13
$(
14
14
$( #[ $inner $( $args) * ] ) *
15
- $variant ,
15
+ $Variant ,
16
16
) +
17
17
}
18
18
19
- impl $name {
19
+ impl $Kind {
20
20
/// Construct a new type from a bit. `None` if unknown.
21
21
pub fn from_bit( bit: u32 ) -> Option <Self > {
22
22
match bit {
23
- $( $bit => Some ( Self :: $variant ) , ) +
23
+ $( $BIT => Some ( Self :: $Variant ) , ) +
24
24
_ => None
25
25
}
26
26
}
27
27
28
28
/// Returns the present bit for the type.
29
29
pub fn bit( & self ) -> u32 {
30
- match self { $( Self :: $variant => $bit , ) + }
30
+ match self { $( Self :: $Variant => $BIT , ) + }
31
31
}
32
32
}
33
33
34
- impl crate :: Kind for $name {
34
+ impl crate :: Kind for $Kind {
35
35
/// Returns the alignment of the field.
36
36
fn align( & self ) -> usize {
37
- match self { $( Self :: $variant => $align , ) + }
37
+ match self { $( Self :: $Variant => $ALIGN , ) + }
38
38
}
39
39
40
40
/// Returns the size of the field.
41
41
fn size( & self ) -> usize {
42
- match self { $( Self :: $variant => $size , ) + }
42
+ match self { $( Self :: $Variant => $SIZE , ) + }
43
43
}
44
44
}
45
45
@@ -49,38 +49,37 @@ macro_rules! impl_kind {
49
49
macro_rules! impl_enum {
50
50
(
51
51
$( #[ $outer: meta] ) *
52
- pub enum $name : ident: $ty: ty{
52
+ pub enum $Field : ident: $ty: ty {
53
53
$(
54
54
$( #[ $inner: ident $( $args: tt) * ] ) *
55
- $variant : ident = $value : expr,
55
+ $Variant : ident = $VALUE : expr,
56
56
) +
57
57
}
58
58
) => {
59
59
$( #[ $outer] ) *
60
- #[ derive( Debug , Clone , PartialEq ) ]
61
- pub enum $name {
60
+ #[ derive( Debug , Clone , Copy , PartialEq ) ]
61
+ pub enum $Field {
62
62
$(
63
63
$( #[ $inner $( $args) * ] ) *
64
- $variant = $value ,
64
+ $Variant = $VALUE ,
65
65
) +
66
66
}
67
67
68
68
#[ allow( dead_code) ]
69
- impl $name {
69
+ impl $Field {
70
70
pub ( crate ) fn from_bits( bits: $ty) -> Option <Self > {
71
71
match bits {
72
72
$(
73
- $value => Some ( Self :: $variant ) ,
73
+ $VALUE => Some ( Self :: $Variant ) ,
74
74
) +
75
75
_ => None
76
76
}
77
77
}
78
78
79
- /// Consumes this field and returns the underlying value.
80
79
pub ( crate ) fn into_inner( self ) -> $ty {
81
80
match self {
82
81
$(
83
- Self :: $variant => $value ,
82
+ Self :: $Variant => $VALUE ,
84
83
) +
85
84
}
86
85
}
@@ -91,21 +90,21 @@ macro_rules! impl_enum {
91
90
macro_rules! impl_newtype {
92
91
(
93
92
$( #[ $outer: meta] ) *
94
- pub struct $name : ident( $ty: ty) ;
93
+ pub struct $Field : ident( $ty: ty) ;
95
94
) => {
96
95
$( #[ $outer] ) *
97
- #[ derive( Debug , Clone , PartialEq ) ]
98
- pub struct $name ( pub ( crate ) $ty) ;
96
+ #[ derive( Debug , Clone , Copy , PartialEq ) ]
97
+ pub struct $Field ( $ty) ;
99
98
100
- impl FromBytes for $name {
99
+ impl frombytes :: FromBytes for $Field {
101
100
type Error = frombytes:: Error ;
102
101
103
102
fn from_bytes( bytes: & mut frombytes:: Bytes ) -> frombytes:: Result <Self > {
104
103
bytes. read( ) . map( Self )
105
104
}
106
105
}
107
106
108
- impl $name {
107
+ impl $Field {
109
108
/// Consumes this field and returns the underlying value.
110
109
#[ inline]
111
110
pub const fn into_inner( self ) -> $ty {
@@ -118,32 +117,32 @@ macro_rules! impl_newtype {
118
117
macro_rules! impl_bitflags {
119
118
(
120
119
$( #[ $outer: meta] ) *
121
- pub struct $name : ident: $ty: ty {
120
+ pub struct $Field : ident: $ty: ty {
122
121
$(
123
122
$( #[ $inner: ident $( $args: tt) * ] ) *
124
- const $flag : ident = $value : expr;
123
+ const $FLAG : ident = $VALUE : expr;
125
124
) +
126
125
}
127
126
) => {
128
127
bitflags:: bitflags! {
129
128
$( #[ $outer] ) *
130
- pub struct $name : $ty {
129
+ pub struct $Field : $ty {
131
130
$(
132
131
$( #[ $inner $( $args) * ] ) *
133
- const $flag = $value ;
132
+ const $FLAG = $VALUE ;
134
133
) +
135
134
}
136
135
}
137
136
138
- impl frombytes:: FromBytes for $name {
137
+ impl frombytes:: FromBytes for $Field {
139
138
type Error = frombytes:: Error ;
140
139
141
140
fn from_bytes( bytes: & mut frombytes:: Bytes ) -> frombytes:: Result <Self > {
142
141
bytes. read( ) . map( Self :: from_bits_truncate)
143
142
}
144
143
}
145
144
146
- impl $name {
145
+ impl $Field {
147
146
/// Consumes this field and returns the underlying value.
148
147
#[ inline]
149
148
pub const fn into_inner( self ) -> $ty {
0 commit comments