|
|
|
@ -182,6 +182,38 @@ pub struct ESock<W, R> {
|
|
|
|
|
|
|
|
|
|
impl<W: AsyncWrite, R: AsyncRead> ESock<W, R>
|
|
|
|
|
{
|
|
|
|
|
/// Move this `ESock`'s state into another with a different reader, returning the new `ESock` and the old reader stream
|
|
|
|
|
pub fn transfer_reader<Rx>(self, rx: Rx) -> (ESock<W, Rx>, (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<Wx>(self, tx: Wx) -> (ESock<Wx, R>, (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<Wx, Rx>(self, tx: Wx, rx: Rx) -> (ESock<Wx, Rx>, (W, R))
|
|
|
|
|
where Wx: AsyncWrite,
|
|
|
|
|