Skip to content

Commit 92c9b34

Browse files
committed
Touch up macros
1 parent a0420b4 commit 92c9b34

File tree

2 files changed

+29
-32
lines changed

2 files changed

+29
-32
lines changed

src/field/_macros.rs

+29-30
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
macro_rules! impl_kind {
22
(
33
$(#[$outer:meta])*
4-
pub enum $name:ident {
4+
pub enum $Kind:ident {
55
$(
66
$(#[$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 },
88
)+
99
}
1010
) => {
1111
$(#[$outer])*
12-
pub enum $name {
12+
pub enum $Kind {
1313
$(
1414
$(#[$inner $($args)*])*
15-
$variant,
15+
$Variant,
1616
)+
1717
}
1818

19-
impl $name {
19+
impl $Kind {
2020
/// Construct a new type from a bit. `None` if unknown.
2121
pub fn from_bit(bit: u32) -> Option<Self> {
2222
match bit {
23-
$( $bit => Some(Self::$variant), )+
23+
$( $BIT => Some(Self::$Variant), )+
2424
_ => None
2525
}
2626
}
2727

2828
/// Returns the present bit for the type.
2929
pub fn bit(&self) -> u32 {
30-
match self { $( Self::$variant => $bit, )+ }
30+
match self { $( Self::$Variant => $BIT, )+ }
3131
}
3232
}
3333

34-
impl crate::Kind for $name {
34+
impl crate::Kind for $Kind {
3535
/// Returns the alignment of the field.
3636
fn align(&self) -> usize {
37-
match self { $( Self::$variant => $align, )+ }
37+
match self { $( Self::$Variant => $ALIGN, )+ }
3838
}
3939

4040
/// Returns the size of the field.
4141
fn size(&self) -> usize {
42-
match self { $( Self::$variant => $size, )+ }
42+
match self { $( Self::$Variant => $SIZE, )+ }
4343
}
4444
}
4545

@@ -49,38 +49,37 @@ macro_rules! impl_kind {
4949
macro_rules! impl_enum {
5050
(
5151
$(#[$outer:meta])*
52-
pub enum $name:ident: $ty:ty{
52+
pub enum $Field:ident: $ty:ty {
5353
$(
5454
$(#[$inner:ident $($args:tt)*])*
55-
$variant:ident = $value:expr,
55+
$Variant:ident = $VALUE:expr,
5656
)+
5757
}
5858
) => {
5959
$(#[$outer])*
60-
#[derive(Debug, Clone, PartialEq)]
61-
pub enum $name {
60+
#[derive(Debug, Clone, Copy, PartialEq)]
61+
pub enum $Field {
6262
$(
6363
$(#[$inner $($args)*])*
64-
$variant = $value,
64+
$Variant = $VALUE,
6565
)+
6666
}
6767

6868
#[allow(dead_code)]
69-
impl $name {
69+
impl $Field {
7070
pub(crate) fn from_bits(bits: $ty) -> Option<Self> {
7171
match bits {
7272
$(
73-
$value => Some(Self::$variant),
73+
$VALUE => Some(Self::$Variant),
7474
)+
7575
_ => None
7676
}
7777
}
7878

79-
/// Consumes this field and returns the underlying value.
8079
pub(crate) fn into_inner(self) -> $ty {
8180
match self {
8281
$(
83-
Self::$variant => $value,
82+
Self::$Variant => $VALUE,
8483
)+
8584
}
8685
}
@@ -91,21 +90,21 @@ macro_rules! impl_enum {
9190
macro_rules! impl_newtype {
9291
(
9392
$(#[$outer:meta])*
94-
pub struct $name:ident($ty:ty);
93+
pub struct $Field:ident($ty:ty);
9594
) => {
9695
$(#[$outer])*
97-
#[derive(Debug, Clone, PartialEq)]
98-
pub struct $name(pub(crate) $ty);
96+
#[derive(Debug, Clone, Copy, PartialEq)]
97+
pub struct $Field($ty);
9998

100-
impl FromBytes for $name {
99+
impl frombytes::FromBytes for $Field {
101100
type Error = frombytes::Error;
102101

103102
fn from_bytes(bytes: &mut frombytes::Bytes) -> frombytes::Result<Self> {
104103
bytes.read().map(Self)
105104
}
106105
}
107106

108-
impl $name {
107+
impl $Field {
109108
/// Consumes this field and returns the underlying value.
110109
#[inline]
111110
pub const fn into_inner(self) -> $ty {
@@ -118,32 +117,32 @@ macro_rules! impl_newtype {
118117
macro_rules! impl_bitflags {
119118
(
120119
$(#[$outer:meta])*
121-
pub struct $name:ident: $ty:ty {
120+
pub struct $Field:ident: $ty:ty {
122121
$(
123122
$(#[$inner:ident $($args:tt)*])*
124-
const $flag:ident = $value:expr;
123+
const $FLAG:ident = $VALUE:expr;
125124
)+
126125
}
127126
) => {
128127
bitflags::bitflags! {
129128
$(#[$outer])*
130-
pub struct $name: $ty {
129+
pub struct $Field: $ty {
131130
$(
132131
$(#[$inner $($args)*])*
133-
const $flag = $value;
132+
const $FLAG = $VALUE;
134133
)+
135134
}
136135
}
137136

138-
impl frombytes::FromBytes for $name {
137+
impl frombytes::FromBytes for $Field {
139138
type Error = frombytes::Error;
140139

141140
fn from_bytes(bytes: &mut frombytes::Bytes) -> frombytes::Result<Self> {
142141
bytes.read().map(Self::from_bits_truncate)
143142
}
144143
}
145144

146-
impl $name {
145+
impl $Field {
147146
/// Consumes this field and returns the underlying value.
148147
#[inline]
149148
pub const fn into_inner(self) -> $ty {

src/field/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ impl VendorNamespace {
125125

126126
impl_enum! {
127127
/// The guard interval.
128-
#[derive(Copy)]
129128
#[non_exhaustive]
130129
pub enum GuardInterval: u8 {
131130
/// 800 ns.
@@ -145,7 +144,6 @@ impl From<bool> for GuardInterval {
145144
}
146145

147146
impl_enum! {
148-
#[derive(Copy)]
149147
/// Forward error correction type.
150148
pub enum Fec: u8 {
151149
/// Binary convolutional coding.

0 commit comments

Comments
 (0)