diff options
author | Azul <azul@riseup.net> | 2020-12-07 16:11:52 +0100 |
---|---|---|
committer | Azul <azul@riseup.net> | 2020-12-08 10:36:04 +0100 |
commit | 88df27d0ae174b87e980371c5600d470516ed116 (patch) | |
tree | 76cd51f47ab8b94b1cd20149d3b328946fc34c3a | |
parent | b956d36cb50cac28aa9da0e373fb33c9a4c120af (diff) |
openpgp: Allow generic types in assert_send_and_sync!.
- Use generics and the anonmymous lifetime in `assert_send_and_sync!`.
- See 627.
-rw-r--r-- | openpgp/src/armor.rs | 2 | ||||
-rw-r--r-- | openpgp/src/cert/amalgamation.rs | 2 | ||||
-rw-r--r-- | openpgp/src/cert/amalgamation/iter.rs | 2 | ||||
-rw-r--r-- | openpgp/src/cert/builder.rs | 2 | ||||
-rw-r--r-- | openpgp/src/cert/bundle.rs | 2 | ||||
-rw-r--r-- | openpgp/src/crypto/aead.rs | 2 | ||||
-rw-r--r-- | openpgp/src/fmt.rs | 2 | ||||
-rw-r--r-- | openpgp/src/macros.rs | 29 | ||||
-rw-r--r-- | openpgp/src/packet/key.rs | 2 | ||||
-rw-r--r-- | openpgp/src/packet/mod.rs | 4 | ||||
-rw-r--r-- | openpgp/src/packet/user_attribute.rs | 2 | ||||
-rw-r--r-- | openpgp/src/parse/map.rs | 2 | ||||
-rw-r--r-- | openpgp/src/policy.rs | 2 | ||||
-rw-r--r-- | openpgp/src/serialize/stream.rs | 2 |
14 files changed, 33 insertions, 24 deletions
diff --git a/openpgp/src/armor.rs b/openpgp/src/armor.rs index e901cc1b..2852ac72 100644 --- a/openpgp/src/armor.rs +++ b/openpgp/src/armor.rs @@ -174,7 +174,7 @@ pub struct Writer<W: Write> { dirty: bool, } -assert_send_and_sync!{Writer<Vec<u8>>} +assert_send_and_sync!{Writer<W>, W: Write} impl<W: Write> Writer<W> { /// Constructs a new filter for the given type of data. diff --git a/openpgp/src/cert/amalgamation.rs b/openpgp/src/cert/amalgamation.rs index 9980784b..69da539a 100644 --- a/openpgp/src/cert/amalgamation.rs +++ b/openpgp/src/cert/amalgamation.rs @@ -647,7 +647,7 @@ pub struct ComponentAmalgamation<'a, C> { cert: &'a Cert, bundle: &'a ComponentBundle<C>, } -assert_send_and_sync!{ComponentAmalgamation<'a, UserID>, 'a} +assert_send_and_sync!{ComponentAmalgamation<'_, C>, C} /// A User ID and its associated data. /// diff --git a/openpgp/src/cert/amalgamation/iter.rs b/openpgp/src/cert/amalgamation/iter.rs index 7af884d3..9e01911c 100644 --- a/openpgp/src/cert/amalgamation/iter.rs +++ b/openpgp/src/cert/amalgamation/iter.rs @@ -90,7 +90,7 @@ pub struct ComponentAmalgamationIter<'a, C> { cert: &'a Cert, iter: slice::Iter<'a, ComponentBundle<C>>, } -assert_send_and_sync!{ComponentAmalgamationIter<'a, UserID>, 'a} +assert_send_and_sync!{ComponentAmalgamationIter<'_, C>, C} /// An iterator over `UserIDAmalgamtion`s. /// diff --git a/openpgp/src/cert/builder.rs b/openpgp/src/cert/builder.rs index b84f02df..9b621b64 100644 --- a/openpgp/src/cert/builder.rs +++ b/openpgp/src/cert/builder.rs @@ -175,7 +175,7 @@ pub struct CertBuilder<'a> { revocation_keys: Option<Vec<RevocationKey>>, phantom: PhantomData<&'a ()>, } -assert_send_and_sync!{CertBuilder<'a>, 'a} +assert_send_and_sync!{CertBuilder<'_>} impl CertBuilder<'_> { /// Returns a new `CertBuilder`. diff --git a/openpgp/src/cert/bundle.rs b/openpgp/src/cert/bundle.rs index d8944777..221c0888 100644 --- a/openpgp/src/cert/bundle.rs +++ b/openpgp/src/cert/bundle.rs @@ -125,7 +125,7 @@ pub struct ComponentBundle<C> { // Third-party revocations (e.g., designated revokers). pub(crate) other_revocations: Vec<Signature>, } -assert_send_and_sync!{ComponentBundle<UserID>} +assert_send_and_sync!{ComponentBundle<C>, C} /// A key (primary or subkey, public or private) and any associated /// signatures. diff --git a/openpgp/src/crypto/aead.rs b/openpgp/src/crypto/aead.rs index d98c8a53..ed773b7d 100644 --- a/openpgp/src/crypto/aead.rs +++ b/openpgp/src/crypto/aead.rs @@ -544,7 +544,7 @@ pub struct Encryptor<W: io::Write> { // A place to write encrypted data into. scratch: Vec<u8>, } -assert_send_and_sync!{Encryptor<Vec<u8>>} +assert_send_and_sync!{Encryptor<W>, W: io::Write} impl<W: io::Write> Encryptor<W> { /// Instantiate a new AEAD encryptor. diff --git a/openpgp/src/fmt.rs b/openpgp/src/fmt.rs index c06c6faf..db372fdf 100644 --- a/openpgp/src/fmt.rs +++ b/openpgp/src/fmt.rs @@ -61,7 +61,7 @@ pub mod hex { offset: usize, } - assert_send_and_sync!{Dumper<Vec<u8>>} + assert_send_and_sync!{Dumper<W>, W: io::Write} impl<W: io::Write> Dumper<W> { /// Creates a new dumper. 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 {} diff --git a/openpgp/src/packet/key.rs b/openpgp/src/packet/key.rs index dae3ff36..da53991d 100644 --- a/openpgp/src/packet/key.rs +++ b/openpgp/src/packet/key.rs @@ -782,7 +782,7 @@ pub struct Key4<P, R> r: std::marker::PhantomData<R>, } -assert_send_and_sync!{Key4<PublicParts, UnspecifiedRole>} +assert_send_and_sync!{Key4<P, R>, P: KeyParts, R: KeyRole} impl<P: KeyParts, R: KeyRole> PartialEq for Key4<P, R> { fn eq(&self, other: &Key4<P, R>) -> bool { diff --git a/openpgp/src/packet/mod.rs b/openpgp/src/packet/mod.rs index 62123105..c4d94b03 100644 --- a/openpgp/src/packet/mod.rs +++ b/openpgp/src/packet/mod.rs @@ -599,7 +599,7 @@ pub struct Iter<'a> { // `paths` iter. depth: usize, } -assert_send_and_sync!{Iter<'a>, 'a} +assert_send_and_sync!{Iter<'_>} impl<'a> Default for Iter<'a> { fn default() -> Self { @@ -1438,7 +1438,7 @@ pub enum Key<P: key::KeyParts, R: key::KeyRole> { /// A version 4 `Key` packet. V4(Key4<P, R>), } -assert_send_and_sync!{Key<key::PublicParts, key::UnspecifiedRole>} +assert_send_and_sync!{Key<P, R>, P: key::KeyParts, R: key::KeyRole} impl<P: key::KeyParts, R: key::KeyRole> fmt::Display for Key<P, R> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/openpgp/src/packet/user_attribute.rs b/openpgp/src/packet/user_attribute.rs index 09fc8749..ec44382a 100644 --- a/openpgp/src/packet/user_attribute.rs +++ b/openpgp/src/packet/user_attribute.rs @@ -118,7 +118,7 @@ impl Arbitrary for UserAttribute { pub struct SubpacketIterator<'a> { reader: buffered_reader::Memory<'a, ()>, } -assert_send_and_sync!{SubpacketIterator<'a>, 'a} +assert_send_and_sync!{SubpacketIterator<'_>} impl<'a> Iterator for SubpacketIterator<'a> { type Item = Result<Subpacket>; diff --git a/openpgp/src/parse/map.rs b/openpgp/src/parse/map.rs index edc6cf4b..3ebcba77 100644 --- a/openpgp/src/parse/map.rs +++ b/openpgp/src/parse/map.rs @@ -114,7 +114,7 @@ pub struct Field<'a> { /// Value of the field. data: &'a [u8], } -assert_send_and_sync!{Field<'a>, 'a} +assert_send_and_sync!{Field<'_>} impl<'a> Field<'a> { fn new(map: &'a Map, i: usize) -> Option<Field<'a>> { diff --git a/openpgp/src/policy.rs b/openpgp/src/policy.rs index f626078b..fc74fe59 100644 --- a/openpgp/src/policy.rs +++ b/openpgp/src/policy.rs @@ -188,7 +188,7 @@ pub struct StandardPolicy<'a> { asymmetric_algos: AsymmetricAlgorithmCutoffList, } -assert_send_and_sync!{StandardPolicy<'a>, 'a} +assert_send_and_sync!{StandardPolicy<'_>} impl<'a> Default for StandardPolicy<'a> { fn default() -> Self { diff --git a/openpgp/src/serialize/stream.rs b/openpgp/src/serialize/stream.rs index 762707ec..f77dfee0 100644 --- a/openpgp/src/serialize/stream.rs +++ b/openpgp/src/serialize/stream.rs @@ -1799,7 +1799,7 @@ pub struct Recipient<'a> { keyid: KeyID, key: &'a Key<key::PublicParts, key::UnspecifiedRole>, } -assert_send_and_sync!{Recipient<'a>, 'a} +assert_send_and_sync!{Recipient<'_>} impl<'a, P, R> From<&'a Key<P, R>> for Recipient<'a> where P: key::KeyParts, |