errore/global/
ctor.rs

1// This is the default implementation for the global module.
2
3extern crate alloc;
4
5use crate::{
6    formatter::{ErrorFormatter, Formatter},
7    subscriber::Subscriber,
8};
9
10inventory::collect!(&'static dyn Subscriber);
11inventory::collect!(&'static dyn Formatter);
12
13#[doc(hidden)]
14#[macro_export]
15macro_rules! impl_subscriber {
16    ($type:expr) => {
17        $crate::__private::submit! {
18            &$type as &dyn $crate::subscriber::Subscriber
19        }
20    };
21}
22
23#[doc(hidden)]
24#[macro_export]
25macro_rules! impl_formatter {
26    ($type:expr) => {
27        $crate::__private::submit! {
28            &$type as &dyn $crate::formatter::Formatter
29        }
30    };
31}
32
33#[inline]
34pub fn for_each_subscriber<F>(f: F)
35where
36    F: FnMut(&'static &dyn Subscriber),
37{
38    inventory::iter::<&'static dyn Subscriber>
39        .into_iter()
40        .for_each(f);
41}
42
43#[doc(hidden)]
44#[inline]
45pub fn get_formatter() -> &'static dyn Formatter {
46    match inventory::iter::<&'static dyn Formatter>.into_iter().last() {
47        Some(v) => *v,
48        None => core::unreachable!("At least one error formatter must exist"),
49    }
50}
51
52inventory::submit! {
53    &ErrorFormatter as &dyn Formatter
54}