kmip_protocol/types/traits.rs
1//! Dynamic traits for sync or async use depending on the Cargo features used.
2//!
3//! The `ReadWrite` trait is the set of traits used by the [Client](crate::client::Client) to read/write to a TLS
4//! stream.
5//!
6//! The exact composition of the set is dependent on the Cargo feature flags used to compile this crate.
7//!
8//! | Feature Flag | Traits included in the `ReadWrite` trait |
9//! |------------------------|------------------------------------------|
10//! | `sync` (default) | `std::io::Read + std::io::Write` |
11//! | `async-with-tokio` | `tokio::io::AsyncReadExt + tokio::io::AsyncWriteExt + std::marker::Unpin` |
12//! | `async-with-async-std` | `async_std::io::ReadExt + async_std::io::WriteExt + std::marker::Unpin` |
13//!
14//! This enables code that is otherwise identical to be re-used.
15
16cfg_if::cfg_if! {
17 if #[cfg(feature = "sync")] {
18 trait_set::trait_set! {
19 pub trait ReadWrite = std::io::Read + std::io::Write;
20 }
21 } else if #[cfg(feature = "async-with-tokio")] {
22 trait_set::trait_set! {
23 pub trait ReadWrite = tokio::io::AsyncReadExt + tokio::io::AsyncWriteExt + std::marker::Unpin;
24 }
25 } else if #[cfg(feature = "async-with-async-std")] {
26 trait_set::trait_set! {
27 pub trait ReadWrite = async_std::io::ReadExt + async_std::io::WriteExt + std::marker::Unpin;
28 }
29 }
30}