summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2020-12-10 09:38:59 +0100
committerAzul <azul@riseup.net>2020-12-10 13:57:19 +0100
commit7176d5746beb8835a1a09e9c3504f7bc8d0da6b3 (patch)
treedb806ebfd3b4ea1c14fab8dfb90a868502481031
parent227db80b9d40526387f1e4a64f90464618fb885b (diff)
openpgp: Add remaining assert_send_and_sync! calls.
- See #615.
-rw-r--r--buffered-reader/src/macros.rs29
-rw-r--r--openpgp/src/armor.rs1
-rw-r--r--openpgp/src/crypto/aead.rs1
-rw-r--r--openpgp/src/macros.rs29
-rw-r--r--openpgp/src/parse.rs3
-rw-r--r--openpgp/src/parse/packet_parser_builder.rs1
-rw-r--r--openpgp/src/parse/packet_pile_parser.rs1
-rw-r--r--openpgp/src/parse/stream.rs7
8 files changed, 58 insertions, 14 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 ) => {
diff --git a/openpgp/src/armor.rs b/openpgp/src/armor.rs
index 88b31a6c..1ef5d5ef 100644
--- a/openpgp/src/armor.rs
+++ b/openpgp/src/armor.rs
@@ -457,6 +457,7 @@ assert_send_and_sync!(ReaderMode);
pub struct Reader<'a> {
reader: buffered_reader::Generic<IoReader<'a>, Cookie>,
}
+assert_send_and_sync!(Reader<'_>);
impl<'a> fmt::Debug for Reader<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
diff --git a/openpgp/src/crypto/aead.rs b/openpgp/src/crypto/aead.rs
index 5e9b5eeb..f26d71fb 100644
--- a/openpgp/src/crypto/aead.rs
+++ b/openpgp/src/crypto/aead.rs
@@ -115,6 +115,7 @@ pub struct Decryptor<'a> {
// Up to a chunk of unread data.
buffer: Vec<u8>,
}
+assert_send_and_sync!(Decryptor<'_>);
impl<'a> Decryptor<'a> {
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 ) => {
diff --git a/openpgp/src/parse.rs b/openpgp/src/parse.rs
index e557850e..968e19b6 100644
--- a/openpgp/src/parse.rs
+++ b/openpgp/src/parse.rs
@@ -3231,6 +3231,7 @@ pub struct PacketParser<'a> {
state: PacketParserState,
}
+assert_send_and_sync!(PacketParser<'_>);
impl<'a> std::fmt::Display for PacketParser<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
@@ -3311,6 +3312,7 @@ pub struct PacketParserEOF<'a> {
reader: Box<dyn BufferedReader<Cookie> + 'a>,
last_path: Vec<usize>,
}
+assert_send_and_sync!(PacketParserEOF<'_>);
impl<'a> PacketParserEOF<'a> {
/// Copies the important information in `pp` into a new
@@ -3572,6 +3574,7 @@ pub enum PacketParserResult<'a> {
/// Information about a fully parsed packet sequence.
EOF(PacketParserEOF<'a>),
}
+assert_send_and_sync!(PacketParserResult<'_>);
impl<'a> PacketParserResult<'a> {
/// Returns `true` if the result is `EOF`.
diff --git a/openpgp/src/parse/packet_parser_builder.rs b/openpgp/src/parse/packet_parser_builder.rs
index 56ea6067..2d7bcad6 100644
--- a/openpgp/src/parse/packet_parser_builder.rs
+++ b/openpgp/src/parse/packet_parser_builder.rs
@@ -96,6 +96,7 @@ pub struct PacketParserBuilder<'a> {
dearmor: Dearmor,
settings: PacketParserSettings,
}
+assert_send_and_sync!(PacketParserBuilder<'_>);
impl<'a> Parse<'a, PacketParserBuilder<'a>> for PacketParserBuilder<'a> {
/// Creates a `PacketParserBuilder` for an OpenPGP message stored
diff --git a/openpgp/src/parse/packet_pile_parser.rs b/openpgp/src/parse/packet_pile_parser.rs
index 4b04fab9..17a2c121 100644
--- a/openpgp/src/parse/packet_pile_parser.rs
+++ b/openpgp/src/parse/packet_pile_parser.rs
@@ -192,6 +192,7 @@ pub struct PacketPileParser<'a> {
/// The packet pile that has been assembled so far.
pile: PacketPile,
}
+assert_send_and_sync!(PacketPileParser<'_>);
impl<'a> Deref for PacketPileParser<'a> {
type Target = PacketParserResult<'a>;
diff --git a/openpgp/src/parse/stream.rs b/openpgp/src/parse/stream.rs
index 7fc2eafb..f799a4ce 100644
--- a/openpgp/src/parse/stream.rs
+++ b/openpgp/src/parse/stream.rs
@@ -986,6 +986,7 @@ impl<V: VerificationHelper> DecryptionHelper for NoDecryptionHelper<V> {
pub struct Verifier<'a, H: VerificationHelper> {
decryptor: Decryptor<'a, NoDecryptionHelper<H>>,
}
+assert_send_and_sync!(Verifier<'_, H> where H: VerificationHelper);
/// A builder for `Verifier`.
///
@@ -999,6 +1000,7 @@ pub struct VerifierBuilder<'a> {
buffer_size: usize,
mapping: bool,
}
+assert_send_and_sync!(VerifierBuilder<'_>);
impl<'a> Parse<'a, VerifierBuilder<'a>>
for VerifierBuilder<'a>
@@ -1395,6 +1397,7 @@ impl<'a, H: VerificationHelper> io::Read for Verifier<'a, H> {
pub struct DetachedVerifier<'a, H: VerificationHelper> {
decryptor: Decryptor<'a, NoDecryptionHelper<H>>,
}
+assert_send_and_sync!(DetachedVerifier<'_, H> where H: VerificationHelper);
/// A builder for `DetachedVerifier`.
///
@@ -1407,6 +1410,7 @@ pub struct DetachedVerifierBuilder<'a> {
signatures: Box<dyn BufferedReader<Cookie> + 'a>,
mapping: bool,
}
+assert_send_and_sync!(DetachedVerifierBuilder<'_>);
impl<'a> Parse<'a, DetachedVerifierBuilder<'a>>
for DetachedVerifierBuilder<'a>
@@ -1749,6 +1753,8 @@ pub struct Decryptor<'a, H: VerificationHelper + DecryptionHelper> {
policy: &'a dyn Policy,
}
+assert_send_and_sync!(Decryptor<'_, H>
+ where H: VerificationHelper + DecryptionHelper);
/// A builder for `Decryptor`.
///
@@ -1762,6 +1768,7 @@ pub struct DecryptorBuilder<'a> {
buffer_size: usize,
mapping: bool,
}
+assert_send_and_sync!(DecryptorBuilder<'_>);
impl<'a> Parse<'a, DecryptorBuilder<'a>>
for DecryptorBuilder<'a>