| 1 | use super::*; |
| 2 | |
| 3 | impl<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)] |
| 10 | macro_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 | |
| 28 | macro_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 |
| 57 | fnptr_format_args! {} |
| 58 | fnptr_format_args! { A } |
| 59 | fnptr_format_args! { A, B } |
| 60 | fnptr_format_args! { A, B, C } |
| 61 | fnptr_format_args! { A, B, C, D } |
| 62 | fnptr_format_args! { A, B, C, D, E } |
| 63 | fnptr_format_args! { A, B, C, D, E, F } |
| 64 | fnptr_format_args! { A, B, C, D, E, F, G } |
| 65 | fnptr_format_args! { A, B, C, D, E, F, G, H } |
| 66 | fnptr_format_args! { A, B, C, D, E, F, G, H, I } |
| 67 | fnptr_format_args! { A, B, C, D, E, F, G, H, I, J } |
| 68 | fnptr_format_args! { A, B, C, D, E, F, G, H, I, J, K } |
| 69 | fnptr_format_args! { A, B, C, D, E, F, G, H, I, J, K, L } |
| 70 | |