core/intrinsics/
macros.rs1macro_rules! intrinsic_dispatch_on_type {
21 (
22 $(#[$attr:meta])*
23 $vis:vis fn $name:ident<$generic:ident: $bound:path>(
24 $($arg:ident: $arg_ty:ty),* $(,)?
25 ) -> $ret_ty:ty;
26 $($concrete:ty => $body:block)*
27 ) => {
28 intrinsic_dispatch_on_type! {
29 @declare [] [] $(#[$attr])*
30 $vis fn $name<$generic: $bound>($($arg: $arg_ty),*) -> $ret_ty;
31 $($concrete => $body)*
32 }
33 };
34
35 (
36 $(#[$attr:meta])*
37 $vis:vis const unsafe fn $name:ident<$generic:ident: $bound:path>(
38 $($arg:ident: $arg_ty:ty),* $(,)?
39 ) -> $ret_ty:ty;
40 $($concrete:ty => $body:block)*
41 ) => {
42 intrinsic_dispatch_on_type! {
43 @declare [const] [unsafe] $(#[$attr])*
44 $vis fn $name<$generic: $bound>($($arg: $arg_ty),*) -> $ret_ty;
45 $($concrete => $body)*
46 }
47 };
48
49 (
50 $(#[$attr:meta])*
51 $vis:vis const fn $name:ident<$generic:ident: $bound:path>(
52 $($arg:ident: $arg_ty:ty),* $(,)?
53 ) -> $ret_ty:ty;
54 $($concrete:ty => $body:block)*
55 ) => {
56 intrinsic_dispatch_on_type! {
57 @declare [const] [] $(#[$attr])*
58 $vis fn $name<$generic: $bound>($($arg: $arg_ty),*) -> $ret_ty;
59 $($concrete => $body)*
60 }
61 };
62
63 (
64 @declare [$($constness:tt)?] [$($safety:tt)?] $(#[$attr:meta])*
65 $vis:vis fn $name:ident<$generic:ident: $bound:path>(
66 $($arg:ident: $arg_ty:ty),*
67 ) -> $ret_ty:ty;
68 $($concrete:ty => $body:block)*
69 ) => {
70 mod $name {
71 use super::*;
72
73 pub trait Dispatch<$generic = Self>: $bound {
74 fn dispatch($($arg: $arg_ty),*) -> $ret_ty;
75 }
76
77 intrinsic_dispatch_on_type! {
78 @impls $generic, ($($arg: $arg_ty),*) -> $ret_ty,
79 $($concrete => $body)*
80 }
81 }
82
83 $(#[$attr])*
84 $vis $($constness)? $($safety)? fn $name<$generic: $name::Dispatch>($($arg: $arg_ty),*) -> $ret_ty {
85 <$generic as $name::Dispatch>::dispatch($($arg),*)
86 }
87 };
88
89 (
90 @impls $generic:ident, $args:tt -> $ret_ty:ty,
91 $($concrete:ty => $body:block)*
92 ) => {
93 $(intrinsic_dispatch_on_type! { @impl $generic = $concrete, $args -> $ret_ty $body })*
94 };
95
96 (
97 @impl $generic:ident = $concrete:ty,
98 ($($arg:ident: $arg_ty:ty),*) -> $ret_ty:ty $body:block
99 ) => {
100 const _: () = {
106 type $generic = $concrete;
107
108 impl Dispatch<$concrete> for $concrete {
109 #[inline]
110 fn dispatch($($arg: $arg_ty),*) -> $ret_ty $body
111 }
112 };
113 };
114}
115
116pub(super) use intrinsic_dispatch_on_type;