Rename EitherSocket to EitherOutput (#201)

This commit is contained in:
Pierre Krieger
2018-05-23 11:45:35 +02:00
committed by GitHub
parent b7065de672
commit a163e81e30
3 changed files with 41 additions and 41 deletions

View File

@ -27,12 +27,12 @@ use tokio_io::{AsyncRead, AsyncWrite};
/// Implements `AsyncRead` and `AsyncWrite` and dispatches all method calls to
/// either `First` or `Second`.
#[derive(Debug, Copy, Clone)]
pub enum EitherSocket<A, B> {
pub enum EitherOutput<A, B> {
First(A),
Second(B),
}
impl<A, B> AsyncRead for EitherSocket<A, B>
impl<A, B> AsyncRead for EitherOutput<A, B>
where
A: AsyncRead,
B: AsyncRead,
@ -40,13 +40,13 @@ where
#[inline]
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [u8]) -> bool {
match self {
&EitherSocket::First(ref a) => a.prepare_uninitialized_buffer(buf),
&EitherSocket::Second(ref b) => b.prepare_uninitialized_buffer(buf),
&EitherOutput::First(ref a) => a.prepare_uninitialized_buffer(buf),
&EitherOutput::Second(ref b) => b.prepare_uninitialized_buffer(buf),
}
}
}
impl<A, B> Read for EitherSocket<A, B>
impl<A, B> Read for EitherOutput<A, B>
where
A: Read,
B: Read,
@ -54,13 +54,13 @@ where
#[inline]
fn read(&mut self, buf: &mut [u8]) -> Result<usize, IoError> {
match self {
&mut EitherSocket::First(ref mut a) => a.read(buf),
&mut EitherSocket::Second(ref mut b) => b.read(buf),
&mut EitherOutput::First(ref mut a) => a.read(buf),
&mut EitherOutput::Second(ref mut b) => b.read(buf),
}
}
}
impl<A, B> AsyncWrite for EitherSocket<A, B>
impl<A, B> AsyncWrite for EitherOutput<A, B>
where
A: AsyncWrite,
B: AsyncWrite,
@ -68,13 +68,13 @@ where
#[inline]
fn shutdown(&mut self) -> Poll<(), IoError> {
match self {
&mut EitherSocket::First(ref mut a) => a.shutdown(),
&mut EitherSocket::Second(ref mut b) => b.shutdown(),
&mut EitherOutput::First(ref mut a) => a.shutdown(),
&mut EitherOutput::Second(ref mut b) => b.shutdown(),
}
}
}
impl<A, B> Write for EitherSocket<A, B>
impl<A, B> Write for EitherOutput<A, B>
where
A: Write,
B: Write,
@ -82,42 +82,42 @@ where
#[inline]
fn write(&mut self, buf: &[u8]) -> Result<usize, IoError> {
match self {
&mut EitherSocket::First(ref mut a) => a.write(buf),
&mut EitherSocket::Second(ref mut b) => b.write(buf),
&mut EitherOutput::First(ref mut a) => a.write(buf),
&mut EitherOutput::Second(ref mut b) => b.write(buf),
}
}
#[inline]
fn flush(&mut self) -> Result<(), IoError> {
match self {
&mut EitherSocket::First(ref mut a) => a.flush(),
&mut EitherSocket::Second(ref mut b) => b.flush(),
&mut EitherOutput::First(ref mut a) => a.flush(),
&mut EitherOutput::Second(ref mut b) => b.flush(),
}
}
}
impl<A, B> StreamMuxer for EitherSocket<A, B>
impl<A, B> StreamMuxer for EitherOutput<A, B>
where
A: StreamMuxer,
B: StreamMuxer,
{
type Substream = EitherSocket<A::Substream, B::Substream>;
type Substream = EitherOutput<A::Substream, B::Substream>;
type InboundSubstream = EitherInbound<A, B>;
type OutboundSubstream = EitherOutbound<A, B>;
#[inline]
fn inbound(self) -> Self::InboundSubstream {
match self {
EitherSocket::First(a) => EitherInbound::A(a.inbound()),
EitherSocket::Second(b) => EitherInbound::B(b.inbound()),
EitherOutput::First(a) => EitherInbound::A(a.inbound()),
EitherOutput::Second(b) => EitherInbound::B(b.inbound()),
}
}
#[inline]
fn outbound(self) -> Self::OutboundSubstream {
match self {
EitherSocket::First(a) => EitherOutbound::A(a.outbound()),
EitherSocket::Second(b) => EitherOutbound::B(b.outbound()),
EitherOutput::First(a) => EitherOutbound::A(a.outbound()),
EitherOutput::Second(b) => EitherOutbound::B(b.outbound()),
}
}
}
@ -133,7 +133,7 @@ where
A: StreamMuxer,
B: StreamMuxer,
{
type Item = Option<EitherSocket<A::Substream, B::Substream>>;
type Item = Option<EitherOutput<A::Substream, B::Substream>>;
type Error = IoError;
#[inline]
@ -141,11 +141,11 @@ where
match *self {
EitherInbound::A(ref mut a) => {
let item = try_ready!(a.poll());
Ok(Async::Ready(item.map(EitherSocket::First)))
Ok(Async::Ready(item.map(EitherOutput::First)))
}
EitherInbound::B(ref mut b) => {
let item = try_ready!(b.poll());
Ok(Async::Ready(item.map(EitherSocket::Second)))
Ok(Async::Ready(item.map(EitherOutput::Second)))
}
}
}
@ -162,7 +162,7 @@ where
A: StreamMuxer,
B: StreamMuxer,
{
type Item = Option<EitherSocket<A::Substream, B::Substream>>;
type Item = Option<EitherOutput<A::Substream, B::Substream>>;
type Error = IoError;
#[inline]
@ -170,11 +170,11 @@ where
match *self {
EitherOutbound::A(ref mut a) => {
let item = try_ready!(a.poll());
Ok(Async::Ready(item.map(EitherSocket::First)))
Ok(Async::Ready(item.map(EitherOutput::First)))
}
EitherOutbound::B(ref mut b) => {
let item = try_ready!(b.poll());
Ok(Async::Ready(item.map(EitherSocket::Second)))
Ok(Async::Ready(item.map(EitherOutput::Second)))
}
}
}
@ -220,7 +220,7 @@ where
A: Future<Item = (Ao, Multiaddr), Error = IoError>,
B: Future<Item = (Bo, Multiaddr), Error = IoError>,
{
type Item = (EitherSocket<Ao, Bo>, Multiaddr);
type Item = (EitherOutput<Ao, Bo>, Multiaddr);
type Error = IoError;
#[inline]
@ -228,11 +228,11 @@ where
match self {
&mut EitherListenUpgrade::First(ref mut a) => {
let (item, addr) = try_ready!(a.poll());
Ok(Async::Ready((EitherSocket::First(item), addr)))
Ok(Async::Ready((EitherOutput::First(item), addr)))
}
&mut EitherListenUpgrade::Second(ref mut b) => {
let (item, addr) = try_ready!(b.poll());
Ok(Async::Ready((EitherSocket::Second(item), addr)))
Ok(Async::Ready((EitherOutput::Second(item), addr)))
}
}
}

View File

@ -18,7 +18,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
use either::{EitherListenStream, EitherListenUpgrade, EitherSocket};
use either::{EitherListenStream, EitherListenUpgrade, EitherOutput};
use futures::prelude::*;
use multiaddr::Multiaddr;
use std::io::Error as IoError;
@ -39,7 +39,7 @@ where
A: Transport,
B: Transport,
{
type Output = EitherSocket<A::Output, B::Output>;
type Output = EitherOutput<A::Output, B::Output>;
type Listener = EitherListenStream<A::Listener, B::Listener>;
type ListenerUpgrade = EitherListenUpgrade<A::ListenerUpgrade, B::ListenerUpgrade>;
type Dial =
@ -93,16 +93,16 @@ where
{
type Incoming = Box<Future<Item = Self::IncomingUpgrade, Error = IoError>>;
type IncomingUpgrade =
Box<Future<Item = (EitherSocket<A::Output, B::Output>, Multiaddr), Error = IoError>>;
Box<Future<Item = (EitherOutput<A::Output, B::Output>, Multiaddr), Error = IoError>>;
#[inline]
fn next_incoming(self) -> Self::Incoming {
let first = self.0.next_incoming().map(|out| {
let fut = out.map(move |(v, addr)| (EitherSocket::First(v), addr));
let fut = out.map(move |(v, addr)| (EitherOutput::First(v), addr));
Box::new(fut) as Box<Future<Item = _, Error = _>>
});
let second = self.1.next_incoming().map(|out| {
let fut = out.map(move |(v, addr)| (EitherSocket::Second(v), addr));
let fut = out.map(move |(v, addr)| (EitherOutput::Second(v), addr));
Box::new(fut) as Box<Future<Item = _, Error = _>>
});
let future = first.select(second).map(|(i, _)| i).map_err(|(e, _)| e);

View File

@ -19,7 +19,7 @@
// DEALINGS IN THE SOFTWARE.
use bytes::Bytes;
use either::EitherSocket;
use either::EitherOutput;
use futures::prelude::*;
use multiaddr::Multiaddr;
use std::io::Error as IoError;
@ -56,7 +56,7 @@ where
}
}
type Output = EitherSocket<A::Output, B::Output>;
type Output = EitherOutput<A::Output, B::Output>;
type Future = EitherConnUpgrFuture<A::Future, B::Future>;
#[inline]
@ -87,7 +87,7 @@ pub enum EitherUpgradeIdentifier<A, B> {
/// Implements `Future` and redirects calls to either `First` or `Second`.
///
/// Additionally, the output will be wrapped inside a `EitherSocket`.
/// Additionally, the output will be wrapped inside a `EitherOutput`.
///
// TODO: This type is needed because of the lack of `impl Trait` in stable Rust.
// If Rust had impl Trait we could use the Either enum from the futures crate and add some
@ -103,7 +103,7 @@ where
A: Future<Error = IoError>,
B: Future<Error = IoError>,
{
type Item = EitherSocket<A::Item, B::Item>;
type Item = EitherOutput<A::Item, B::Item>;
type Error = IoError;
#[inline]
@ -111,11 +111,11 @@ where
match self {
&mut EitherConnUpgrFuture::First(ref mut a) => {
let item = try_ready!(a.poll());
Ok(Async::Ready(EitherSocket::First(item)))
Ok(Async::Ready(EitherOutput::First(item)))
}
&mut EitherConnUpgrFuture::Second(ref mut b) => {
let item = try_ready!(b.poll());
Ok(Async::Ready(EitherSocket::Second(item)))
Ok(Async::Ready(EitherOutput::Second(item)))
}
}
}