1use crate::{
2 FnPtr, HasAbi, HasSafety,
3 marker::{self, Safe, Unsafe},
4};
5
6pub trait WithAbi<Abi>: FnPtr
8where
9 Abi: marker::Abi,
10{
11 type F: FnPtr<
13 Args = Self::Args,
14 Output = Self::Output,
15 ArityMarker = Self::ArityMarker,
16 SafetyMarker = Self::SafetyMarker,
17 AbiMarker = Abi,
18 > + HasAbi<Abi>;
19}
20
21pub trait WithSafety<Safety>: FnPtr
23where
24 Safety: marker::Safety,
25{
26 type F: FnPtr<
28 Args = Self::Args,
29 Output = Self::Output,
30 ArityMarker = Self::ArityMarker,
31 SafetyMarker = Safety,
32 AbiMarker = Self::AbiMarker,
33 > + HasSafety<Safety>;
34}
35
36pub trait AsSafe: WithSafety<Safe> {}
38impl<F: WithSafety<Safe>> AsSafe for F {}
39
40pub trait AsUnsafe: WithSafety<Unsafe> {}
42impl<F: WithSafety<Unsafe>> AsUnsafe for F {}
43
44cfg_tt::cfg_tt! {
45pub trait Convertible:
47 FnPtr
48 + WithAbi<marker::Rust>
49 + WithAbi<marker::C>
50 + WithAbi<marker::CUnwind>
51 + WithAbi<marker::System>
52 + WithAbi<marker::SystemUnwind>
53 + WithSafety<marker::Safe>
54 + WithSafety<marker::Unsafe>
55 + AsSafe
56 + AsUnsafe
57 #[cfg(has_abi_aapcs)](+ WithAbi<marker::Aapcs>)
58 #[cfg(has_abi_aapcs)](+ WithAbi<marker::AapcsUnwind>)
59 #[cfg(has_abi_cdecl)](+ WithAbi<marker::Cdecl>)
60 #[cfg(has_abi_cdecl)](+ WithAbi<marker::CdeclUnwind>)
61 #[cfg(has_abi_stdcall)](+ WithAbi<marker::Stdcall>)
62 #[cfg(has_abi_stdcall)](+ WithAbi<marker::StdcallUnwind>)
63 #[cfg(has_abi_fastcall)](+ WithAbi<marker::Fastcall>)
64 #[cfg(has_abi_fastcall)](+ WithAbi<marker::FastcallUnwind>)
65 #[cfg(has_abi_thiscall)](+ WithAbi<marker::Thiscall>)
66 #[cfg(has_abi_thiscall)](+ WithAbi<marker::ThiscallUnwind>)
67 #[cfg(has_abi_vectorcall)](+ WithAbi<marker::Vectorcall>)
68 #[cfg(has_abi_vectorcall)](+ WithAbi<marker::VectorcallUnwind>)
69 #[cfg(has_abi_sysv64)](+ WithAbi<marker::SysV64>)
70 #[cfg(has_abi_sysv64)](+ WithAbi<marker::SysV64Unwind>)
71 #[cfg(has_abi_win64)](+ WithAbi<marker::Win64>)
72 #[cfg(has_abi_win64)](+ WithAbi<marker::Win64Unwind>)
73{
74}
75impl<T> Convertible for T
76where
77 T: FnPtr
78 + WithAbi<marker::Rust>
79 + WithAbi<marker::C>
80 + WithAbi<marker::CUnwind>
81 + WithAbi<marker::System>
82 + WithAbi<marker::SystemUnwind>
83 + WithSafety<marker::Safe>
84 + WithSafety<marker::Unsafe>
85 + AsSafe
86 + AsUnsafe
87 #[cfg(has_abi_aapcs)](+ WithAbi<marker::Aapcs>)
88 #[cfg(has_abi_aapcs)](+ WithAbi<marker::AapcsUnwind>)
89 #[cfg(has_abi_cdecl)](+ WithAbi<marker::Cdecl>)
90 #[cfg(has_abi_cdecl)](+ WithAbi<marker::CdeclUnwind>)
91 #[cfg(has_abi_stdcall)](+ WithAbi<marker::Stdcall>)
92 #[cfg(has_abi_stdcall)](+ WithAbi<marker::StdcallUnwind>)
93 #[cfg(has_abi_fastcall)](+ WithAbi<marker::Fastcall>)
94 #[cfg(has_abi_fastcall)](+ WithAbi<marker::FastcallUnwind>)
95 #[cfg(has_abi_thiscall)](+ WithAbi<marker::Thiscall>)
96 #[cfg(has_abi_thiscall)](+ WithAbi<marker::ThiscallUnwind>)
97 #[cfg(has_abi_vectorcall)](+ WithAbi<marker::Vectorcall>)
98 #[cfg(has_abi_vectorcall)](+ WithAbi<marker::VectorcallUnwind>)
99 #[cfg(has_abi_sysv64)](+ WithAbi<marker::SysV64>)
100 #[cfg(has_abi_sysv64)](+ WithAbi<marker::SysV64Unwind>)
101 #[cfg(has_abi_win64)](+ WithAbi<marker::Win64>)
102 #[cfg(has_abi_win64)](+ WithAbi<marker::Win64Unwind>)
103{}
104}
105
106#[macro_export]
126macro_rules! with_abi {
127 ( $abi:path, $ty:ty ) => {
129 <$ty as $crate::WithAbi<$abi>>::F
130 };
131
132 ( $abi_lit:tt, $ty:ty ) => {
134 <$ty as $crate::WithAbi<$crate::abi!($abi_lit)>>::F
135 };
136}
137
138#[macro_export]
150macro_rules! make_safe {
151 ( $ty:ty ) => {
152 <$ty as $crate::WithSafety<$crate::marker::Safe>>::F
153 };
154}
155
156#[macro_export]
168macro_rules! make_unsafe {
169 ( $ty:ty ) => {
170 <$ty as $crate::WithSafety<$crate::marker::Unsafe>>::F
171 };
172}