Skip to content

Commit e67c40b

Browse files
Better const pattern example
1 parent c233d4d commit e67c40b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

text/0000-inline-const.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,16 @@ fn mock_ip(use_localhost: bool) -> &'static Ipv6Addr {
2222
}
2323
}
2424

25+
const MMIO_BIT1: u8 = 4;
26+
const MMIO_BIT2: u8 = 5;
27+
2528
fn main() {
26-
match *x {
27-
0 ..= const { u32::MAX / 2 } => println!("low"),
28-
const { u32::MAX / 2 + 1 } ..= u32::MAX => println!("high"),
29+
match read_mmio() {
30+
0 => {}
31+
const { 1 << MMIO_BIT1 } => println!("FOO"),
32+
const { 1 << MMIO_BIT2 } => println!("BAR"),
33+
34+
_ => unreachable!(),
2935
}
3036
}
3137
```

0 commit comments

Comments
 (0)