mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-13 01:51:23 +00:00
core/muxing: Replace Into<io::Error>
bound on StreamMuxer
with std::error::Error
(#2710)
* core/muxing: Remove `Into<io::Error>` bound from `StreamMuxer::Error` This allows us to preserve the type information of a muxer's concrete error as long as possible. For `StreamMuxerBox`, we leverage `io::Error`'s capability of wrapping any error that implements `Into<Box<dyn Error>>`. * Use `?` in `Connection::poll` * Use `?` in `muxing::boxed::Wrap` * Use `futures::ready!` in `muxing::boxed::Wrap` * Fill PR number into changelog * Put `Error + Send + Sync` bounds directly on `StreamMuxer::Error` * Move `Send + Sync` bounds to higher layers * Use `map_inbound_stream` helper * Update changelog to match new implementation
This commit is contained in:
@ -203,7 +203,7 @@ where
|
||||
{
|
||||
type Substream = EitherOutput<A::Substream, B::Substream>;
|
||||
type OutboundSubstream = EitherOutbound<A, B>;
|
||||
type Error = io::Error;
|
||||
type Error = EitherError<A::Error, B::Error>;
|
||||
|
||||
fn poll_event(
|
||||
&self,
|
||||
@ -212,11 +212,11 @@ where
|
||||
match self {
|
||||
EitherOutput::First(inner) => inner
|
||||
.poll_event(cx)
|
||||
.map_err(|e| e.into())
|
||||
.map_err(EitherError::A)
|
||||
.map_ok(|event| event.map_inbound_stream(EitherOutput::First)),
|
||||
EitherOutput::Second(inner) => inner
|
||||
.poll_event(cx)
|
||||
.map_err(|e| e.into())
|
||||
.map_err(EitherError::B)
|
||||
.map_ok(|event| event.map_inbound_stream(EitherOutput::Second)),
|
||||
}
|
||||
}
|
||||
@ -237,11 +237,11 @@ where
|
||||
(EitherOutput::First(ref inner), EitherOutbound::A(ref mut substream)) => inner
|
||||
.poll_outbound(cx, substream)
|
||||
.map(|p| p.map(EitherOutput::First))
|
||||
.map_err(|e| e.into()),
|
||||
.map_err(EitherError::A),
|
||||
(EitherOutput::Second(ref inner), EitherOutbound::B(ref mut substream)) => inner
|
||||
.poll_outbound(cx, substream)
|
||||
.map(|p| p.map(EitherOutput::Second))
|
||||
.map_err(|e| e.into()),
|
||||
.map_err(EitherError::B),
|
||||
_ => panic!("Wrong API usage"),
|
||||
}
|
||||
}
|
||||
@ -261,8 +261,8 @@ where
|
||||
|
||||
fn poll_close(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
match self {
|
||||
EitherOutput::First(inner) => inner.poll_close(cx).map_err(|e| e.into()),
|
||||
EitherOutput::Second(inner) => inner.poll_close(cx).map_err(|e| e.into()),
|
||||
EitherOutput::First(inner) => inner.poll_close(cx).map_err(EitherError::A),
|
||||
EitherOutput::Second(inner) => inner.poll_close(cx).map_err(EitherError::B),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user