bool_type!(pubEncrypted;"Is the value encrypted?");
bool_type!(pubEncrypted;"Is the value encrypted?");
bool_type!(pubEncryption;"What way are we en/decrypting?"=>Encrypt,Decrypt);
bool_type!(pubEncryption;"What way are we en/decrypting?"=>Encrypt,Decrypt);
/// A wrapper `AsyncWrite` stream that allows switching between encrypted (chacha20stream) and plain stream writing.
///
/// # Polymorphic dispatching
/// While this type implements `AsyncWrite` itself, it is recommended to use the polymorphic mutable reference returned by `as_dyn_unpin_mut()` (or `as_dyn_mut()` for non-`Unpin` values of `S`) for writing if lots of `AsyncWrite` methods will be dispatched on the instance.
/// This will prevent the need to check the discriminant of the enum each time the `DualStream`'s `AsyncWrite` methods are polled.
/// The type implements `AsRef/Mut` for streams `S` that are both `Unpin` and not `Unpin` for convenience.
#[derive(Debug)]
#[derive(Debug)]
pubenumDualStream<S>
pubenumDualStream<S: AsyncWrite>
{
{
/// If there is a panic while switching modes, the stream is left in this invariant state.
/// If there is a panic while switching modes, the stream is left in this invariant state.
///
/// Stream `S` is dropped if the instance is in this state.
Poisoned,
Poisoned,
/// Stream `S` is being written to through a chacha20stream `AsyncSink` stream cipher.
Encrypted(AsyncSink<S>),
Encrypted(AsyncSink<S>),
/// Stream `S` is being written to directly.
Plain(S),
Plain(S),
}
}
// We can use dynamic dispatching to prevent the need to check the enum's discriminant each time. (In theory. It might not be that useful unless we add `Unpin` here too. TODO: Check this later.)
// We can use dynamic dispatching to prevent the need to check the enum's discriminant each time.
// We have `AsRef/Mut`s for normal and `Unpin` polymorphic `AsyncWrite`s