Skip to content

Commit 23748d5

Browse files
Split out const fn example
1 parent fb2ab59 commit 23748d5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

posts/inside-rust/2019-11-23-const-if-match.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ static PLATFORM: &str = if cfg!(unix) {
1919
"other"
2020
};
2121

22+
const _: () = assert!(std::mem::size_of::<usize>() == 8, "Only 64-bit platforms are supported");
23+
```
24+
25+
`if` and `match` can also be used in the body of a `const fn`:
26+
27+
```rust
2228
const fn gcd(a: u32, b: u32) -> u32 {
2329
match (a, b) {
2430
(x, 0) | (0, x) => x,
@@ -30,8 +36,6 @@ const fn gcd(a: u32, b: u32) -> u32 {
3036
(x, y) => gcd((x-y)/2, y),
3137
}
3238
}
33-
34-
const _: () = assert!(std::mem::size_of::<usize>() == 8, "Only 64-bit platforms are supported");
3539
```
3640

3741
## What exactly is going on here?

0 commit comments

Comments
 (0)