Skip to content

Commit f90861c

Browse files
committed
non_exhaustive unit structs
1 parent 6b1690f commit f90861c

File tree

4 files changed

+56
-76
lines changed

4 files changed

+56
-76
lines changed

src/afio.rs

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@ impl AfioExt for AFIO {
1818
AFIO::reset(rcc);
1919

2020
Parts {
21-
evcr: EVCR { _0: () },
22-
mapr: MAPR {
23-
_0: (),
24-
jtag_enabled: true,
25-
},
26-
exticr1: EXTICR1 { _0: () },
27-
exticr2: EXTICR2 { _0: () },
28-
exticr3: EXTICR3 { _0: () },
29-
exticr4: EXTICR4 { _0: () },
30-
mapr2: MAPR2 { _0: () },
21+
evcr: EVCR,
22+
mapr: MAPR { jtag_enabled: true },
23+
exticr1: EXTICR1,
24+
exticr2: EXTICR2,
25+
exticr3: EXTICR3,
26+
exticr4: EXTICR4,
27+
mapr2: MAPR2,
3128
}
3229
}
3330
}
@@ -51,9 +48,8 @@ pub struct Parts {
5148
pub mapr2: MAPR2,
5249
}
5350

54-
pub struct EVCR {
55-
_0: (),
56-
}
51+
#[non_exhaustive]
52+
pub struct EVCR;
5753

5854
impl EVCR {
5955
pub fn evcr(&mut self) -> &afio::EVCR {
@@ -71,8 +67,8 @@ impl EVCR {
7167
/// let mut afio = dp.AFIO.constrain();
7268
/// function_using_mapr(&mut afio.mapr);
7369
/// ```
70+
#[non_exhaustive]
7471
pub struct MAPR {
75-
_0: (),
7672
jtag_enabled: bool,
7773
}
7874

@@ -111,49 +107,44 @@ impl MAPR {
111107
}
112108
}
113109

114-
pub struct EXTICR1 {
115-
_0: (),
116-
}
110+
#[non_exhaustive]
111+
pub struct EXTICR1;
117112

118113
impl EXTICR1 {
119114
pub fn exticr1(&mut self) -> &afio::EXTICR1 {
120115
unsafe { (*AFIO::ptr()).exticr1() }
121116
}
122117
}
123118

124-
pub struct EXTICR2 {
125-
_0: (),
126-
}
119+
#[non_exhaustive]
120+
pub struct EXTICR2;
127121

128122
impl EXTICR2 {
129123
pub fn exticr2(&mut self) -> &afio::EXTICR2 {
130124
unsafe { (*AFIO::ptr()).exticr2() }
131125
}
132126
}
133127

134-
pub struct EXTICR3 {
135-
_0: (),
136-
}
128+
#[non_exhaustive]
129+
pub struct EXTICR3;
137130

138131
impl EXTICR3 {
139132
pub fn exticr3(&mut self) -> &afio::EXTICR3 {
140133
unsafe { (*AFIO::ptr()).exticr3() }
141134
}
142135
}
143136

144-
pub struct EXTICR4 {
145-
_0: (),
146-
}
137+
#[non_exhaustive]
138+
pub struct EXTICR4;
147139

148140
impl EXTICR4 {
149141
pub fn exticr4(&mut self) -> &afio::EXTICR4 {
150142
unsafe { (*AFIO::ptr()).exticr4() }
151143
}
152144
}
153145

154-
pub struct MAPR2 {
155-
_0: (),
156-
}
146+
#[non_exhaustive]
147+
pub struct MAPR2;
157148

158149
impl MAPR2 {
159150
pub fn mapr2(&mut self) -> &afio::MAPR2 {

src/dma.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ macro_rules! dma {
137137
/// A singleton that represents a single DMAx channel (channel X in this case)
138138
///
139139
/// This singleton has exclusive access to the registers of the DMAx channel X
140-
pub struct $CX { _0: () }
140+
#[non_exhaustive]
141+
pub struct $CX;
141142

142143
impl $CX {
143144
/// Associated peripheral `address`
@@ -456,7 +457,7 @@ macro_rules! dma {
456457
self.$chX().cr().reset();
457458
)+
458459

459-
Channels((), $($CX { _0: () }),+)
460+
Channels((), $($CX),+)
460461
}
461462
}
462463
}

src/flash.rs

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,14 @@ pub trait FlashExt {
309309
impl FlashExt for FLASH {
310310
fn constrain(self) -> Parts {
311311
Parts {
312-
acr: ACR { _0: () },
313-
ar: AR { _0: () },
314-
cr: CR { _0: () },
315-
keyr: KEYR { _0: () },
316-
_obr: OBR { _0: () },
317-
_optkeyr: OPTKEYR { _0: () },
318-
sr: SR { _0: () },
319-
_wrpr: WRPR { _0: () },
312+
acr: ACR,
313+
ar: AR,
314+
cr: CR,
315+
keyr: KEYR,
316+
_obr: OBR,
317+
_optkeyr: OPTKEYR,
318+
sr: SR,
319+
_wrpr: WRPR,
320320
}
321321
}
322322
}
@@ -359,9 +359,8 @@ impl Parts {
359359
}
360360

361361
/// Opaque ACR register
362-
pub struct ACR {
363-
_0: (),
364-
}
362+
#[non_exhaustive]
363+
pub struct ACR;
365364

366365
#[allow(dead_code)]
367366
impl ACR {
@@ -372,9 +371,8 @@ impl ACR {
372371
}
373372

374373
/// Opaque AR register
375-
pub struct AR {
376-
_0: (),
377-
}
374+
#[non_exhaustive]
375+
pub struct AR;
378376

379377
#[allow(dead_code)]
380378
impl AR {
@@ -385,9 +383,8 @@ impl AR {
385383
}
386384

387385
/// Opaque CR register
388-
pub struct CR {
389-
_0: (),
390-
}
386+
#[non_exhaustive]
387+
pub struct CR;
391388

392389
#[allow(dead_code)]
393390
impl CR {
@@ -398,9 +395,8 @@ impl CR {
398395
}
399396

400397
/// Opaque KEYR register
401-
pub struct KEYR {
402-
_0: (),
403-
}
398+
#[non_exhaustive]
399+
pub struct KEYR;
404400

405401
#[allow(dead_code)]
406402
impl KEYR {
@@ -411,9 +407,8 @@ impl KEYR {
411407
}
412408

413409
/// Opaque OBR register
414-
pub struct OBR {
415-
_0: (),
416-
}
410+
#[non_exhaustive]
411+
pub struct OBR;
417412

418413
#[allow(dead_code)]
419414
impl OBR {
@@ -424,9 +419,8 @@ impl OBR {
424419
}
425420

426421
/// Opaque OPTKEYR register
427-
pub struct OPTKEYR {
428-
_0: (),
429-
}
422+
#[non_exhaustive]
423+
pub struct OPTKEYR;
430424

431425
#[allow(dead_code)]
432426
impl OPTKEYR {
@@ -437,9 +431,8 @@ impl OPTKEYR {
437431
}
438432

439433
/// Opaque SR register
440-
pub struct SR {
441-
_0: (),
442-
}
434+
#[non_exhaustive]
435+
pub struct SR;
443436

444437
#[allow(dead_code)]
445438
impl SR {
@@ -450,9 +443,8 @@ impl SR {
450443
}
451444

452445
/// Opaque WRPR register
453-
pub struct WRPR {
454-
_0: (),
455-
}
446+
#[non_exhaustive]
447+
pub struct WRPR;
456448

457449
#[allow(dead_code)]
458450
impl WRPR {

src/rcc.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl RccExt for RCC {
2929
sysclk: None,
3030
adcclk: None,
3131
},
32-
bkp: BKP { _0: () },
32+
bkp: BKP,
3333
}
3434
}
3535
}
@@ -49,9 +49,8 @@ pub struct Rcc {
4949
}
5050

5151
/// AMBA High-performance Bus (AHB) registers
52-
pub struct AHB {
53-
_0: (),
54-
}
52+
#[non_exhaustive]
53+
pub struct AHB;
5554

5655
impl AHB {
5756
fn enr(rcc: &rcc::RegisterBlock) -> &rcc::AHBENR {
@@ -60,9 +59,8 @@ impl AHB {
6059
}
6160

6261
/// Advanced Peripheral Bus 1 (APB1) registers
63-
pub struct APB1 {
64-
_0: (),
65-
}
62+
#[non_exhaustive]
63+
pub struct APB1;
6664

6765
impl APB1 {
6866
fn enr(rcc: &rcc::RegisterBlock) -> &rcc::APB1ENR {
@@ -83,9 +81,8 @@ impl APB1 {
8381
}
8482

8583
/// Advanced Peripheral Bus 2 (APB2) registers
86-
pub struct APB2 {
87-
_0: (),
88-
}
84+
#[non_exhaustive]
85+
pub struct APB2;
8986

9087
impl APB2 {
9188
fn enr(rcc: &rcc::RegisterBlock) -> &rcc::APB2ENR {
@@ -319,9 +316,8 @@ impl CFGR {
319316
}
320317
}
321318

322-
pub struct BKP {
323-
_0: (),
324-
}
319+
#[non_exhaustive]
320+
pub struct BKP;
325321

326322
impl BKP {
327323
/// Enables write access to the registers in the backup domain

0 commit comments

Comments
 (0)