diff options
Diffstat (limited to 'openpgp/src/macros.rs')
-rw-r--r-- | openpgp/src/macros.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/openpgp/src/macros.rs b/openpgp/src/macros.rs index 822312f2..7bc93b01 100644 --- a/openpgp/src/macros.rs +++ b/openpgp/src/macros.rs @@ -108,3 +108,45 @@ macro_rules! time_it { time_it!("", $body) }; } + +/// A simple shortcut for ensuring a type is send and sync. +/// +/// For most types just call it after defining the type: +/// +/// ``` +/// pub struct MyStruct {} +/// assert_send_and_sync!{MyStruct} +/// ``` +/// +/// For types with lifetimes, specify the lifetime as a second argument: +/// +/// ``` +/// pub struct WithLifetime<'a> {} +/// assert_send_and_sync!{MyStruct, 'a} +/// ``` +/// +/// For types generic over other types, call it with a concrete type: +/// +/// ``` +/// pub struct MyWriter<W: io::Write> {} +/// assert_send_and_sync!{MyWriterStruct<Vec<u8>>} +/// ``` +/// +/// You can also combine the two: +/// +/// ``` +/// pub struct MyWriterWithLifetime<a', W: io::Write> {} +/// assert_send_and_sync!{MyWriterStruct<a', Vec<u8>>, a'} +/// ``` +/// +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 ) => { + impl crate::types::Sendable for $x {} + impl crate::types::Syncable for $x {} + }; +} + |