summaryrefslogtreecommitdiffstats
path: root/openpgp/src/macros.rs
diff options
context:
space:
mode:
Diffstat (limited to 'openpgp/src/macros.rs')
-rw-r--r--openpgp/src/macros.rs29
1 files changed, 22 insertions, 7 deletions
diff --git a/openpgp/src/macros.rs b/openpgp/src/macros.rs
index d350a09b..1714fa1b 100644
--- a/openpgp/src/macros.rs
+++ b/openpgp/src/macros.rs
@@ -126,31 +126,46 @@ macro_rules! time_it {
/// ```
///
/// For a type generic over another type `W`,
-/// pass the type `W` as a second argument
+/// pass the type `W` as a where clause
/// including a trait bound when needed:
///
/// ```
/// pub struct MyWriter<W: io::Write> {}
-/// assert_send_and_sync!(MyWriterStruct<W>, W: io::Write);
+/// assert_send_and_sync!(MyWriterStruct<W> where W: io::Write);
/// ```
///
/// This will assert that `MyWriterStruct<W>` is `Send` and `Sync`
/// if `W` is `Send` and `Sync`.
///
-/// You can also combine the two and be generic over multiple types:
+/// You can also combine the two and be generic over multiple types.
+/// Just make sure to list all the types - even those without additional
+/// trait bounds:
///
/// ```
/// pub struct MyWriterWithLifetime<a', C, W: io::Write> {}
-/// assert_send_and_sync!(MyWriterStruct<'_, C, W>, C, W: io::Write);
+/// assert_send_and_sync!(MyWriterStruct<'_, C, W> where C, W: io::Write);
/// ```
///
+/// If you need multiple additional trait bounds on a single type
+/// you can add them separated by `+` like in normal where clauses.
+/// However you have to make sure they are `Identifiers` like `Write`.
+/// In macro patterns `Paths` (like `io::Write`) may not be followed
+/// by `+` characters.
macro_rules! assert_send_and_sync {
- ( $x:ty where $( $g:ident$( : $b:path )? $(,)?)*) => {
+ ( $x:ty where $( $g:ident$( : $a:path )? $(,)?)*) => {
impl<$( $g ),*> crate::types::Sendable for $x
- where $( $g: Send + Sync $(+ $b)? ),*
+ where $( $g: Send + Sync $( + $a )? ),*
{}
impl<$( $g ),*> crate::types::Syncable for $x
- where $( $g: Send + Sync $(+ $b)? ),*
+ where $( $g: Send + Sync $( + $a )? ),*
+ {}
+ };
+ ( $x:ty where $( $g:ident$( : $a:ident $( + $b:ident )* )? $(,)?)*) => {
+ impl<$( $g ),*> crate::types::Sendable for $x
+ where $( $g: Send + Sync $( + $a $( + $b )* )? ),*
+ {}
+ impl<$( $g ),*> crate::types::Syncable for $x
+ where $( $g: Send + Sync $( + $a $( + $b )* )? ),*
{}
};
( $x:ty ) => {