1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2025 Nathan Sizemore <nathanrsizemore@gmail.com>
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at http://mozilla.org/MPL/2.0/.
/// Debug-only assertion that a raw pointer is not null.
///
/// Expands to a `debug_assert!` that checks `!$ptr.is_null()`.
/// Like `debug_assert!`, this **only runs in non-optimized builds**
/// (i.e., when `debug_assertions` are enabled) and is a no-op in
/// release builds.
///
/// Two forms are supported:
/// 1) `debug_assert_not_null!(ptr);` — prints a default message with the
/// pointer expression’s name via `stringify!`.
/// 2) `debug_assert_not_null!(ptr, "custom {}", msg);` — custom message.
///
/// ### Parameters
/// - `$ptr`: an expression of type `*const T` or `*mut T`.
///
/// ### Example
/// ```rust
/// # use std::ptr;
/// # use your_crate::debug_assert_not_null;
/// let p: *mut u8 = 0x1 as *mut u8;
/// debug_assert_not_null!(p);
///
/// let q: *const u8 = ptr::null();
/// // This will panic in debug builds:
/// // debug_assert_not_null!(q, "q must be valid before FFI call");
/// ```