mirror of
https://github.com/italicsjenga/gba.git
synced 2025-01-11 19:41:30 +11:00
clarification to const_assert
This commit is contained in:
parent
51d3915dea
commit
09c16ef1b0
|
@ -52,11 +52,11 @@ name.
|
||||||
const _: usize = 0 - 1;
|
const _: usize = 0 - 1;
|
||||||
```
|
```
|
||||||
|
|
||||||
Now we wrap this in a macro where we give an expression for a bool. We negate
|
Now we wrap this in a macro where we give a `bool` expression as input. We
|
||||||
the bool then cast it to a `usize`, meaning that `true` negates into `false`,
|
negate the bool then cast it to a `usize`, meaning that `true` negates into
|
||||||
which becomes `0usize`, and then there's no underflow error. Or if the input was
|
`false`, which becomes `0usize`, and then there's no underflow error. Or if the
|
||||||
`false`, it negates into `true`, then becomes `1usize`, and then the underflow
|
input was `false`, it negates into `true`, then becomes `1usize`, and then the
|
||||||
error fires.
|
underflow error fires.
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
macro_rules! const_assert {
|
macro_rules! const_assert {
|
||||||
|
@ -68,8 +68,14 @@ macro_rules! const_assert {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
This allows anything which supports `core::ops::Not` and can then can cast into
|
Technically, written like this, the expression can be anything with a
|
||||||
`usize`, which technically isn't just `bool` values, but close enough.
|
`core::ops::Not` implementation that can also be `as` cast into `usize`. That's
|
||||||
|
`bool`, but also basically all the other number types.
|
||||||
|
|
||||||
|
It doesn't really hurt if you want to `const_assert!` a number I guess. I mean,
|
||||||
|
any number other than the `MAX` value of an unsigned type or the `-1` value of
|
||||||
|
an unsigned type will fail such an assertion, but I bet you'll notice that you
|
||||||
|
did something wrong pretty quick.
|
||||||
|
|
||||||
## Asserting Something
|
## Asserting Something
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue