#[doc(alias = "@protocol")]
#[macro_export]
macro_rules! extern_protocol {
(
$(#[$m:meta])*
$v:vis unsafe trait $name:ident $(: $conforms_to:ident $(+ $conforms_to_rest:ident)*)? {
$($methods:tt)*
}
$(#[$impl_m:meta])*
unsafe impl ProtocolType for dyn $for:ident {
$(const NAME: &'static str = $name_const:expr;)?
}
) => {
$(#[$m])*
$v unsafe trait $name $(: $conforms_to $(+ $conforms_to_rest)*)? {
$crate::__extern_protocol_rewrite_methods! {
$($methods)*
}
}
$crate::__inner_extern_protocol!(
($(#[$impl_m])*)
($name)
(dyn $for)
($crate::__select_name!($name; $($name_const)?))
);
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __inner_extern_protocol {
(
($(#[$impl_m:meta])*)
($name:ident)
(dyn $for:ident)
($name_str:expr)
) => {
$(#[$impl_m])*
unsafe impl<T> $name for $crate::runtime::ProtocolObject<T>
where
T: ?$crate::__macro_helpers::Sized + $crate::ProtocolType + $name
{}
$(#[$impl_m])*
unsafe impl ProtocolType for dyn $for {
const NAME: &'static $crate::__macro_helpers::str = $name_str;
const __INNER: () = ();
}
$(#[$impl_m])*
unsafe impl<T> $crate::runtime::ImplementedBy<T> for dyn $for
where
T: ?$crate::__macro_helpers::Sized + $crate::Message + $name
{
const __INNER: () = ();
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __extern_protocol_rewrite_methods {
{} => {};
{
$(#[$($m:tt)*])*
$v:vis unsafe fn $name:ident($($args:tt)*) $(-> $ret:ty)?
$(where $($where:ty : $bound:path),+ $(,)?)?;
$($rest:tt)*
} => {
$crate::__rewrite_self_arg! {
($($args)*)
($crate::__extract_custom_attributes)
($(#[$($m)*])*)
($name)
($crate::__extern_protocol_method_out)
($v unsafe fn $name($($args)*) $(-> $ret)?)
($($($where : $bound ,)+)?)
}
$crate::__extern_protocol_rewrite_methods! {
$($rest)*
}
};
{
$(#[$($m:tt)*])*
$v:vis fn $name:ident($($args:tt)*) $(-> $ret:ty)?
$(where $($where:ty : $bound:path),+ $(,)?)?;
$($rest:tt)*
} => {
$crate::__rewrite_self_arg! {
($($args)*)
($crate::__extract_custom_attributes)
($(#[$($m)*])*)
($name)
($crate::__extern_protocol_method_out)
($v fn $name($($args)*) $(-> $ret)?)
($($($where : $bound ,)+)?)
}
$crate::__extern_protocol_rewrite_methods! {
$($rest)*
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __extern_protocol_method_out {
{
($($function_start:tt)*)
($($where:ty : $bound:path ,)*)
(add_method)
($receiver:expr)
($__receiver_ty:ty)
($($__args_prefix:tt)*)
($($args_rest:tt)*)
(#[method($($sel:tt)*)])
($($m_optional:tt)*)
($($m_checked:tt)*)
} => {
$($m_checked)*
$($function_start)*
where
Self: $crate::__macro_helpers::Sized + $crate::Message
$(, $where : $bound)*
{
#[allow(unused_unsafe)]
unsafe {
$crate::__method_msg_send! {
($receiver)
($($sel)*)
($($args_rest)*)
()
()
}
}
}
};
{
($($function_start:tt)*)
($($where:ty : $bound:path ,)*)
(add_method)
($receiver:expr)
($__receiver_ty:ty)
($($__args_prefix:tt)*)
($($args_rest:tt)*)
(#[method_id($($sel:tt)*)])
($($m_optional:tt)*)
($($m_checked:tt)*)
} => {
$($m_checked)*
$($function_start)*
where
Self: $crate::__macro_helpers::Sized + $crate::Message
$(, $where : $bound)*
{
#[allow(unused_unsafe)]
unsafe {
$crate::__method_msg_send_id! {
($receiver)
($($sel)*)
($($args_rest)*)
()
()
()
}
}
}
};
{
($($function_start:tt)*)
($($where:ty : $bound:path ,)*)
(add_class_method)
($receiver:expr)
($__receiver_ty:ty)
($($__args_prefix:tt)*)
($($args_rest:tt)*)
(#[method($($sel:tt)*)])
($($m_optional:tt)*)
($($m_checked:tt)*)
} => {
$($m_checked)*
$($function_start)*
where
Self: $crate::__macro_helpers::Sized + $crate::ClassType
$(, $where : $bound)*
{
#[allow(unused_unsafe)]
unsafe {
$crate::__method_msg_send! {
($receiver)
($($sel)*)
($($args_rest)*)
()
()
}
}
}
};
{
($($function_start:tt)*)
($($where:ty : $bound:path ,)*)
(add_class_method)
($receiver:expr)
($__receiver_ty:ty)
($($__args_prefix:tt)*)
($($args_rest:tt)*)
(#[method_id($($sel:tt)*)])
($($m_optional:tt)*)
($($m_checked:tt)*)
} => {
$($m_checked)*
$($function_start)*
where
Self: $crate::__macro_helpers::Sized + $crate::ClassType
$(, $where : $bound)*
{
#[allow(unused_unsafe)]
unsafe {
$crate::__method_msg_send_id! {
($receiver)
($($sel)*)
($($args_rest)*)
()
()
()
}
}
}
};
}