macro_rules! assert_send_and_sync {
( $x:ty where $( $g:ident$( : $a:path )? $(,)?)*) => {
impl<$( $g ),*> crate::macros::Sendable for $x
where $( $g: Send + Sync $( + $a )? ),*
{}
impl<$( $g ),*> crate::macros::Syncable for $x
where $( $g: Send + Sync $( + $a )? ),*
{}
};
( $x:ty where $( $g:ident$( : $a:ident $( + $b:ident )* )? $(,)?)*) => {
impl<$( $g ),*> crate::macros::Sendable for $x
where $( $g: Send + Sync $( + $a $( + $b )* )? ),*
{}
impl<$( $g ),*> crate::macros::Syncable for $x
where $( $g: Send + Sync $( + $a $( + $b )* )? ),*
{}
};
( $x:ty ) => {
impl crate::macros::Sendable for $x {}
impl crate::macros::Syncable for $x {}
};
}
pub(crate) trait Sendable : Send {}
pub(crate) trait Syncable : Sync {}
#[cfg(test)]
mod test {
pub struct MyStruct {}
assert_send_and_sync!(MyStruct);
pub struct WithLifetime<'a> { _p: std::marker::PhantomData<&'a ()> }
assert_send_and_sync!(WithLifetime<'_>);
pub struct MyWriter<W: std::io::Write> { _p: std::marker::PhantomData<W> }
assert_send_and_sync!(MyWriter<W> where W: std::io::Write);
pub struct MyWriterWithLifetime<'a, C, W: std::io::Write> {
_p: std::marker::PhantomData<&'a (C, W)>,
}
assert_send_and_sync!(MyWriterWithLifetime<'_, C, W> where C, W: std::io::Write);
}