wgpu_types/
assertions.rs

1//! Macros for validation internal to the wgpu.
2//!
3//! This module defines assertion macros that respect `wgpu-type`'s
4//! `"strict_asserts"` feature.
5//!
6//! Because `wgpu-core`'s public APIs validate their arguments in all
7//! types of builds, for performance, the `track` module skips some of
8//! Rust's usual run-time checks on its internal operations in release
9//! builds. However, some `wgpu-core` applications have a strong
10//! preference for robustness over performance. To accommodate them,
11//! `wgpu-core`'s `"strict_asserts"` feature enables that validation
12//! in both debug and release builds.
13
14/// This is equivalent to [`std::assert`] if the `strict_asserts` feature is activated, otherwise equal to [`std::debug_assert`].
15#[cfg(feature = "strict_asserts")]
16#[macro_export]
17macro_rules! strict_assert {
18    ( $( $arg:tt )* ) => {
19        assert!( $( $arg )* )
20    }
21}
22
23/// This is equivalent to [`std::assert_eq`] if the `strict_asserts` feature is activated, otherwise equal to [`std::debug_assert_eq`].
24#[cfg(feature = "strict_asserts")]
25#[macro_export]
26macro_rules! strict_assert_eq {
27    ( $( $arg:tt )* ) => {
28        assert_eq!( $( $arg )* )
29    }
30}
31
32/// This is equivalent to [`std::assert_ne`] if the `strict_asserts` feature is activated, otherwise equal to [`std::debug_assert_ne`].
33#[cfg(feature = "strict_asserts")]
34#[macro_export]
35macro_rules! strict_assert_ne {
36    ( $( $arg:tt )* ) => {
37        assert_ne!( $( $arg )* )
38    }
39}
40
41/// This is equivalent to [`std::assert`] if the `strict_asserts` feature is activated, otherwise equal to [`std::debug_assert`]
42#[cfg(not(feature = "strict_asserts"))]
43#[macro_export]
44macro_rules! strict_assert {
45    ( $( $arg:tt )* ) => {
46        debug_assert!( $( $arg )* )
47    };
48}
49
50/// This is equivalent to [`std::assert_eq`] if the `strict_asserts` feature is activated, otherwise equal to [`std::debug_assert_eq`]
51#[cfg(not(feature = "strict_asserts"))]
52#[macro_export]
53macro_rules! strict_assert_eq {
54    ( $( $arg:tt )* ) => {
55        debug_assert_eq!( $( $arg )* )
56    };
57}
58
59/// This is equivalent to [`std::assert_ne`] if the `strict_asserts` feature is activated, otherwise equal to [`std::debug_assert_ne`]
60#[cfg(not(feature = "strict_asserts"))]
61#[macro_export]
62macro_rules! strict_assert_ne {
63    ( $( $arg:tt )* ) => {
64        debug_assert_ne!( $( $arg )* )
65    };
66}