I am using futures::sync::mpsc::UnboundedSender to send message.
Now I need add ChaCha encryption for its unbounded_send
method. Hence I creates a warpper structure for it.
struct EncryptionSender {
inner: futures01::sync::mpsc::UnboundedSender<Bytes>,
cipher : ChaCha12,
}
impl EncryptionSender {
pub fn new(cipher:ChaCha12, tx: futures01::sync::mpsc::UnboundedSender<Bytes>) -> Self {
EncryptionSender {
cipher : cipher,
inner : tx,
}
}
pub fn unbounded_send(&self, msg: Bytes) -> Result<(), SendError<Bytes>> {
self.cipher.apply_keystream(&msg);
self.inner.unbounded_send(msg);
}
pub fn is_closed(&self) -> bool {
self.inner.is_closed()
}
}
This way is not good because I have to implement all other methods(e.g. is_closed
) of inner
What is the proper way for this purpose?