diff --git a/src/sock/enc.rs b/src/sock/enc.rs index 2553e6c..1b24592 100644 --- a/src/sock/enc.rs +++ b/src/sock/enc.rs @@ -182,6 +182,38 @@ pub struct ESock { impl ESock { + /// Move this `ESock`'s state into another with a different reader, returning the new `ESock` and the old reader stream + pub fn transfer_reader(self, rx: Rx) -> (ESock, (R,)) + where Rx: AsyncRead + { + let ESock { info, state, rx: orx, tx } = self; + + let (orx, rx) = { + let (s, c) = orx.into_parts(); + + (s, AsyncSource::from_parts(rx, c)) + }; + + (ESock { + state, info, tx, rx + }, (orx,)) + } + /// Move this `ESock`'s state into another with a different writer, returning the new `ESock` and the old writer stream + pub fn transfer_writer(self, tx: Wx) -> (ESock, (W,)) + where Wx: AsyncWrite + { + let ESock { info, state, rx, tx: otx } = self; + + let (otx, tx) = { + let (s, c) = otx.into_parts(); + + (s, AsyncSink::from_parts(tx, c)) + }; + + (ESock { + info, state, tx, rx + }, (otx,)) + } /// Move this `ESock`'s state into another, returning the new `ESock` and the old streams pub fn transfer_state(self, tx: Wx, rx: Rx) -> (ESock, (W, R)) where Wx: AsyncWrite,