nichlink_debug_method/collector.rs
1//! Debug-only linker-section backend for NichLink declarations.
2//! 仅调试期使用的 NichLink 声明链接段后端。
3
4/// Iterate every declaration that opted into the debug collector in this
5/// binary; outside debug builds the result is empty rather than absent.
6/// 遍历本二进制中选择加入调试收集器的所有声明;非调试构建下结果为空而非缺失。
7#[macro_export]
8macro_rules! registrations {
9 ($ty:ty) => {{
10 #[cfg(debug_assertions)]
11 {
12 $crate::inventory::iter::<$crate::CollectedRegistration>
13 .into_iter()
14 .map(|entry| entry.0)
15 }
16 #[cfg(not(debug_assertions))]
17 {
18 std::iter::empty::<&'static $ty>()
19 }
20 }};
21}
22
23/// Submit one `'static` registration value to the debug collector; the value
24/// stays in the binary's inventory section and is only read in debug builds.
25/// 向调试收集器提交一个 `'static` 注册值;该值留在二进制的 inventory 段中,
26/// 仅在调试构建中被读取。
27#[macro_export]
28macro_rules! submit {
29 ($value:expr) => {
30 $crate::inventory::submit! {
31 $crate::CollectedRegistration(&$value)
32 }
33 };
34}