diff options
author | Azul <azul@riseup.net> | 2020-12-10 09:38:59 +0100 |
---|---|---|
committer | Azul <azul@riseup.net> | 2020-12-10 13:57:19 +0100 |
commit | 7176d5746beb8835a1a09e9c3504f7bc8d0da6b3 (patch) | |
tree | db806ebfd3b4ea1c14fab8dfb90a868502481031 /buffered-reader/src | |
parent | 227db80b9d40526387f1e4a64f90464618fb885b (diff) |
openpgp: Add remaining assert_send_and_sync! calls.
- See #615.
Diffstat (limited to 'buffered-reader/src')
-rw-r--r-- | buffered-reader/src/macros.rs | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/buffered-reader/src/macros.rs b/buffered-reader/src/macros.rs index ff30d6fb..d6792648 100644 --- a/buffered-reader/src/macros.rs +++ b/buffered-reader/src/macros.rs @@ -15,31 +15,46 @@ /// ``` /// /// 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::macros::Sendable for $x - where $( $g: Send + Sync $(+ $b)? ),* + where $( $g: Send + Sync $( + $a )? ),* {} impl<$( $g ),*> crate::macros::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::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 ) => { |