mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
Since `wgpu-core`'s public functions are supposed to validate their parameters, the internal `track` module skips many of Rust's usual run-time checks in release builds. However, some `wgpu-core` users are happy to pay the performance cost in exchange for more safety. The `"strict_asserts"` feature causes `wgpu_core` to perform the same checks in release builds as it does in debug builds.
50 lines
1.3 KiB
Rust
50 lines
1.3 KiB
Rust
//! Macros for validation internal to the resource tracker.
|
|
//!
|
|
//! This module defines assertion macros that respect `wgpu-core`'s
|
|
//! `"strict_asserts"` feature.
|
|
//!
|
|
//! Because `wgpu-core`'s public APIs validate their arguments in all
|
|
//! types of builds, for performance, the `track` module skips some of
|
|
//! Rust's usual run-time checks on its internal operations in release
|
|
//! builds. However, some `wgpu-core` applications have a strong
|
|
//! preference for robustness over performance. To accommodate them,
|
|
//! `wgpu-core`'s `"strict_asserts"` feature enables that validation
|
|
//! in both debug and release builds.
|
|
|
|
#[cfg(feature = "strict_asserts")]
|
|
macro_rules! strict_assert {
|
|
( $( $arg:tt )* ) => {
|
|
assert!( $( $arg )* )
|
|
}
|
|
}
|
|
|
|
#[cfg(feature = "strict_asserts")]
|
|
macro_rules! strict_assert_eq {
|
|
( $( $arg:tt )* ) => {
|
|
assert_eq!( $( $arg )* )
|
|
}
|
|
}
|
|
|
|
#[cfg(feature = "strict_asserts")]
|
|
macro_rules! strict_assert_ne {
|
|
( $( $arg:tt )* ) => {
|
|
assert_ne!( $( $arg )* )
|
|
}
|
|
}
|
|
|
|
#[cfg(not(feature = "strict_asserts"))]
|
|
#[macro_export]
|
|
macro_rules! strict_assert {
|
|
( $( $arg:tt )* ) => {};
|
|
}
|
|
|
|
#[cfg(not(feature = "strict_asserts"))]
|
|
macro_rules! strict_assert_eq {
|
|
( $( $arg:tt )* ) => {};
|
|
}
|
|
|
|
#[cfg(not(feature = "strict_asserts"))]
|
|
macro_rules! strict_assert_ne {
|
|
( $( $arg:tt )* ) => {};
|
|
}
|