defmt/impls/core_/
ptr.rs

1use super::*;
2
3impl<T> Format for core::ptr::NonNull<T> {
4    fn format(&self, fmt: Formatter) {
5        crate::write!(fmt, "{}", self.as_ptr())
6    }
7}
8
9#[cfg(c_variadic)]
10macro_rules! fnptr_format_cvariadic {
11    ($($Arg:ident),+) => {
12        impl<Ret, $($Arg),*> Format for extern "C" fn($($Arg),* , ...) -> Ret {
13            fn format(&self, fmt: Formatter) {
14                crate::write!(fmt, "{}", (*self as usize) as *const ())
15            }
16        }
17        impl<Ret, $($Arg),*> Format for unsafe extern "C" fn($($Arg),* , ...) -> Ret {
18            fn format(&self, fmt: Formatter) {
19                crate::write!(fmt, "{}", (*self as usize) as *const ())
20            }
21        }
22    };
23    () => {
24        // C variadics require at least one other argument
25    };
26}
27
28macro_rules! fnptr_format_args {
29    ($($Arg:ident),*) => {
30        impl<Ret, $($Arg),*> Format for extern "Rust" fn($($Arg),*) -> Ret {
31            fn format(&self, fmt: Formatter) {
32                crate::write!(fmt, "{}", (*self as usize) as *const ())
33            }
34        }
35        impl<Ret, $($Arg),*> Format for extern "C" fn($($Arg),*) -> Ret {
36            fn format(&self, fmt: Formatter) {
37                crate::write!(fmt, "{}", (*self as usize) as *const ())
38            }
39        }
40        impl<Ret, $($Arg),*> Format for unsafe extern "Rust" fn($($Arg),*) -> Ret {
41            fn format(&self, fmt: Formatter) {
42                crate::write!(fmt, "{}", (*self as usize) as *const ())
43            }
44        }
45        impl<Ret, $($Arg),*> Format for unsafe extern "C" fn($($Arg),*) -> Ret {
46            fn format(&self, fmt: Formatter) {
47                crate::write!(fmt, "{}", (*self as usize) as *const ())
48            }
49        }
50        #[cfg(c_variadic)]
51        fnptr_format_cvariadic!{ $($Arg),* }
52    };
53}
54
55// core::ptr has fnptr impls up to 12 arguments
56// https://doc.rust-lang.org/src/core/ptr/mod.rs.html#1994
57fnptr_format_args! {}
58fnptr_format_args! { A }
59fnptr_format_args! { A, B }
60fnptr_format_args! { A, B, C }
61fnptr_format_args! { A, B, C, D }
62fnptr_format_args! { A, B, C, D, E }
63fnptr_format_args! { A, B, C, D, E, F }
64fnptr_format_args! { A, B, C, D, E, F, G }
65fnptr_format_args! { A, B, C, D, E, F, G, H }
66fnptr_format_args! { A, B, C, D, E, F, G, H, I }
67fnptr_format_args! { A, B, C, D, E, F, G, H, I, J }
68fnptr_format_args! { A, B, C, D, E, F, G, H, I, J, K }
69fnptr_format_args! { A, B, C, D, E, F, G, H, I, J, K, L }