summaryrefslogtreecommitdiffstats
path: root/openpgp/src/macros.rs
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2020-12-07 16:11:52 +0100
committerAzul <azul@riseup.net>2020-12-08 10:36:04 +0100
commit88df27d0ae174b87e980371c5600d470516ed116 (patch)
tree76cd51f47ab8b94b1cd20149d3b328946fc34c3a /openpgp/src/macros.rs
parentb956d36cb50cac28aa9da0e373fb33c9a4c120af (diff)
openpgp: Allow generic types in assert_send_and_sync!.
- Use generics and the anonmymous lifetime in `assert_send_and_sync!`. - See 627.
Diffstat (limited to 'openpgp/src/macros.rs')
-rw-r--r--openpgp/src/macros.rs29
1 files changed, 19 insertions, 10 deletions
diff --git a/openpgp/src/macros.rs b/openpgp/src/macros.rs
index 7bc93b01..23167c4e 100644
--- a/openpgp/src/macros.rs
+++ b/openpgp/src/macros.rs
@@ -118,31 +118,40 @@ macro_rules! time_it {
/// assert_send_and_sync!{MyStruct}
/// ```
///
-/// For types with lifetimes, specify the lifetime as a second argument:
+/// For types with lifetimes, use the anonymous lifetime:
///
/// ```
/// pub struct WithLifetime<'a> {}
-/// assert_send_and_sync!{MyStruct, 'a}
+/// assert_send_and_sync!{MyStruct<'_>}
/// ```
///
-/// For types generic over other types, call it with a concrete type:
+/// For a type generic over another type `W`,
+/// pass the type `W` as a second argument
+/// including a trait bound when needed:
///
/// ```
/// pub struct MyWriter<W: io::Write> {}
-/// assert_send_and_sync!{MyWriterStruct<Vec<u8>>}
+/// assert_send_and_sync!{MyWriterStruct<W>, W: io::Write}
/// ```
///
-/// You can also combine the two:
+/// 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:
///
/// ```
-/// pub struct MyWriterWithLifetime<a', W: io::Write> {}
-/// assert_send_and_sync!{MyWriterStruct<a', Vec<u8>>, a'}
+/// pub struct MyWriterWithLifetime<a', C, W: io::Write> {}
+/// assert_send_and_sync!{MyWriterStruct<'_, C, W>, C, W: io::Write}
/// ```
///
macro_rules! assert_send_and_sync {
- ( $x:ty, $l:lifetime ) => {
- impl<$l> crate::types::Sendable for $x {}
- impl<$l> crate::types::Syncable for $x {}
+ ( $x:ty, $( $g:ident$( : $b:path )? ),*) => {
+ impl<$( $g ),*> crate::types::Sendable for $x
+ where $( $g: Send + Sync $(+ $b)? ),*
+ {}
+ impl<$( $g ),*> crate::types::Syncable for $x
+ where $( $g: Send + Sync $(+ $b)? ),*
+ {}
};
( $x:ty ) => {
impl crate::types::Sendable for $x {}