mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-13 01:51:23 +00:00
core/muxing: Force StreamMuxer::Substream
to implement Async{Read,Write}
(#2707)
Co-authored-by: Max Inden <mail@max-inden.de>
This commit is contained in:
@ -259,85 +259,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn read_substream(
|
||||
&self,
|
||||
cx: &mut Context<'_>,
|
||||
sub: &mut Self::Substream,
|
||||
buf: &mut [u8],
|
||||
) -> Poll<Result<usize, Self::Error>> {
|
||||
match (self, sub) {
|
||||
(EitherOutput::First(ref inner), EitherOutput::First(ref mut sub)) => {
|
||||
inner.read_substream(cx, sub, buf).map_err(|e| e.into())
|
||||
}
|
||||
(EitherOutput::Second(ref inner), EitherOutput::Second(ref mut sub)) => {
|
||||
inner.read_substream(cx, sub, buf).map_err(|e| e.into())
|
||||
}
|
||||
_ => panic!("Wrong API usage"),
|
||||
}
|
||||
}
|
||||
|
||||
fn write_substream(
|
||||
&self,
|
||||
cx: &mut Context<'_>,
|
||||
sub: &mut Self::Substream,
|
||||
buf: &[u8],
|
||||
) -> Poll<Result<usize, Self::Error>> {
|
||||
match (self, sub) {
|
||||
(EitherOutput::First(ref inner), EitherOutput::First(ref mut sub)) => {
|
||||
inner.write_substream(cx, sub, buf).map_err(|e| e.into())
|
||||
}
|
||||
(EitherOutput::Second(ref inner), EitherOutput::Second(ref mut sub)) => {
|
||||
inner.write_substream(cx, sub, buf).map_err(|e| e.into())
|
||||
}
|
||||
_ => panic!("Wrong API usage"),
|
||||
}
|
||||
}
|
||||
|
||||
fn flush_substream(
|
||||
&self,
|
||||
cx: &mut Context<'_>,
|
||||
sub: &mut Self::Substream,
|
||||
) -> Poll<Result<(), Self::Error>> {
|
||||
match (self, sub) {
|
||||
(EitherOutput::First(ref inner), EitherOutput::First(ref mut sub)) => {
|
||||
inner.flush_substream(cx, sub).map_err(|e| e.into())
|
||||
}
|
||||
(EitherOutput::Second(ref inner), EitherOutput::Second(ref mut sub)) => {
|
||||
inner.flush_substream(cx, sub).map_err(|e| e.into())
|
||||
}
|
||||
_ => panic!("Wrong API usage"),
|
||||
}
|
||||
}
|
||||
|
||||
fn shutdown_substream(
|
||||
&self,
|
||||
cx: &mut Context<'_>,
|
||||
sub: &mut Self::Substream,
|
||||
) -> Poll<Result<(), Self::Error>> {
|
||||
match (self, sub) {
|
||||
(EitherOutput::First(ref inner), EitherOutput::First(ref mut sub)) => {
|
||||
inner.shutdown_substream(cx, sub).map_err(|e| e.into())
|
||||
}
|
||||
(EitherOutput::Second(ref inner), EitherOutput::Second(ref mut sub)) => {
|
||||
inner.shutdown_substream(cx, sub).map_err(|e| e.into())
|
||||
}
|
||||
_ => panic!("Wrong API usage"),
|
||||
}
|
||||
}
|
||||
|
||||
fn destroy_substream(&self, substream: Self::Substream) {
|
||||
match self {
|
||||
EitherOutput::First(inner) => match substream {
|
||||
EitherOutput::First(substream) => inner.destroy_substream(substream),
|
||||
_ => panic!("Wrong API usage"),
|
||||
},
|
||||
EitherOutput::Second(inner) => match substream {
|
||||
EitherOutput::Second(substream) => inner.destroy_substream(substream),
|
||||
_ => panic!("Wrong API usage"),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
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()),
|
||||
|
Reference in New Issue
Block a user