mirror of
https://github.com/italicsjenga/gba.git
synced 2024-12-23 19:01:30 +11:00
assert upgrades!
This commit is contained in:
parent
3d2dbbf214
commit
9e3b3e15f1
|
@ -72,15 +72,20 @@ macro_rules! const_assert {
|
||||||
|
|
||||||
Technically, written like this, the expression can be anything with a
|
Technically, written like this, the expression can be anything with a
|
||||||
`core::ops::Not` implementation that can also be `as` cast into `usize`. That's
|
`core::ops::Not` implementation that can also be `as` cast into `usize`. That's
|
||||||
`bool`, but also basically all the other number types.
|
`bool`, but also basically all the other number types. Since we want to ensure
|
||||||
|
that we get proper looking type errors when things go wrong, we can use
|
||||||
|
`($condition && true)` to enforce that we get a `bool` (thanks to `Talchas` for
|
||||||
|
that particular suggestion).
|
||||||
|
|
||||||
It doesn't really hurt if you want to `const_assert!` a number I guess. I mean,
|
```rust
|
||||||
any number other than the `MAX` value of an unsigned type or the `-1` value of
|
macro_rules! const_assert {
|
||||||
an unsigned type will fail such an assertion, but I bet you'll notice that you
|
($condition:expr) => {
|
||||||
did something wrong pretty quick. We could use the
|
#[deny(const_err)]
|
||||||
[type_ascription](https://github.com/rust-lang/rust/issues/23416) feature to
|
#[allow(dead_code)]
|
||||||
really force a `bool`, but it's not that critical, so we'll avoid using a
|
const _: usize = 0 - !($condition && true) as usize;
|
||||||
feature that we don't need until it's stable.
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Asserting Something
|
## Asserting Something
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue