mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-05-17 05:11:19 +00:00
core/muxing: Drop Unpin
requirement from SubstreamBox
(#2762)
We are already boxing the given object so we might as well pin to to avoid the `Unpin` trait bound.
This commit is contained in:
parent
51a847128c
commit
f15a3dc4e0
@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
- Remove `StreamMuxer::poll_event` in favor of individual functions: `poll_inbound`, `poll_outbound`
|
- Remove `StreamMuxer::poll_event` in favor of individual functions: `poll_inbound`, `poll_outbound`
|
||||||
and `poll_address_change`. Consequently, `StreamMuxerEvent` is also removed. See [PR 2724].
|
and `poll_address_change`. Consequently, `StreamMuxerEvent` is also removed. See [PR 2724].
|
||||||
|
- Drop `Unpin` requirement from `SubstreamBox`. See [PR XXXX.
|
||||||
|
|
||||||
[PR 2724]: https://github.com/libp2p/rust-libp2p/pull/2724
|
[PR 2724]: https://github.com/libp2p/rust-libp2p/pull/2724
|
||||||
|
[PR XXXX]: https://github.com/libp2p/rust-libp2p/pull/XXXX
|
||||||
|
|
||||||
# 0.34.0
|
# 0.34.0
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ pub struct StreamMuxerBox {
|
|||||||
///
|
///
|
||||||
/// A [`SubstreamBox`] erases the concrete type it is given and only retains its `AsyncRead`
|
/// A [`SubstreamBox`] erases the concrete type it is given and only retains its `AsyncRead`
|
||||||
/// and `AsyncWrite` capabilities.
|
/// and `AsyncWrite` capabilities.
|
||||||
pub struct SubstreamBox(Box<dyn AsyncReadWrite + Send + Unpin>);
|
pub struct SubstreamBox(Pin<Box<dyn AsyncReadWrite + Send>>);
|
||||||
|
|
||||||
struct Wrap<T>
|
struct Wrap<T>
|
||||||
where
|
where
|
||||||
@ -106,8 +106,8 @@ impl StreamMuxer for StreamMuxerBox {
|
|||||||
|
|
||||||
impl SubstreamBox {
|
impl SubstreamBox {
|
||||||
/// Construct a new [`SubstreamBox`] from something that implements [`AsyncRead`] and [`AsyncWrite`].
|
/// Construct a new [`SubstreamBox`] from something that implements [`AsyncRead`] and [`AsyncWrite`].
|
||||||
pub fn new<S: AsyncRead + AsyncWrite + Send + Unpin + 'static>(stream: S) -> Self {
|
pub fn new<S: AsyncRead + AsyncWrite + Send + 'static>(stream: S) -> Self {
|
||||||
Self(Box::new(stream))
|
Self(Box::pin(stream))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +118,7 @@ impl fmt::Debug for SubstreamBox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Workaround because Rust does not allow `Box<dyn AsyncRead + AsyncWrite>`.
|
/// Workaround because Rust does not allow `Box<dyn AsyncRead + AsyncWrite>`.
|
||||||
trait AsyncReadWrite: AsyncRead + AsyncWrite + Unpin {
|
trait AsyncReadWrite: AsyncRead + AsyncWrite {
|
||||||
/// Helper function to capture the erased inner type.
|
/// Helper function to capture the erased inner type.
|
||||||
///
|
///
|
||||||
/// Used to make the [`Debug`] implementation of [`SubstreamBox`] more useful.
|
/// Used to make the [`Debug`] implementation of [`SubstreamBox`] more useful.
|
||||||
@ -127,7 +127,7 @@ trait AsyncReadWrite: AsyncRead + AsyncWrite + Unpin {
|
|||||||
|
|
||||||
impl<S> AsyncReadWrite for S
|
impl<S> AsyncReadWrite for S
|
||||||
where
|
where
|
||||||
S: AsyncRead + AsyncWrite + Unpin,
|
S: AsyncRead + AsyncWrite,
|
||||||
{
|
{
|
||||||
fn type_name(&self) -> &'static str {
|
fn type_name(&self) -> &'static str {
|
||||||
std::any::type_name::<S>()
|
std::any::type_name::<S>()
|
||||||
@ -136,44 +136,44 @@ where
|
|||||||
|
|
||||||
impl AsyncRead for SubstreamBox {
|
impl AsyncRead for SubstreamBox {
|
||||||
fn poll_read(
|
fn poll_read(
|
||||||
self: Pin<&mut Self>,
|
mut self: Pin<&mut Self>,
|
||||||
cx: &mut Context<'_>,
|
cx: &mut Context<'_>,
|
||||||
buf: &mut [u8],
|
buf: &mut [u8],
|
||||||
) -> Poll<std::io::Result<usize>> {
|
) -> Poll<std::io::Result<usize>> {
|
||||||
Pin::new(&mut self.get_mut().0).poll_read(cx, buf)
|
self.0.as_mut().poll_read(cx, buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll_read_vectored(
|
fn poll_read_vectored(
|
||||||
self: Pin<&mut Self>,
|
mut self: Pin<&mut Self>,
|
||||||
cx: &mut Context<'_>,
|
cx: &mut Context<'_>,
|
||||||
bufs: &mut [IoSliceMut<'_>],
|
bufs: &mut [IoSliceMut<'_>],
|
||||||
) -> Poll<std::io::Result<usize>> {
|
) -> Poll<std::io::Result<usize>> {
|
||||||
Pin::new(&mut self.get_mut().0).poll_read_vectored(cx, bufs)
|
self.0.as_mut().poll_read_vectored(cx, bufs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsyncWrite for SubstreamBox {
|
impl AsyncWrite for SubstreamBox {
|
||||||
fn poll_write(
|
fn poll_write(
|
||||||
self: Pin<&mut Self>,
|
mut self: Pin<&mut Self>,
|
||||||
cx: &mut Context<'_>,
|
cx: &mut Context<'_>,
|
||||||
buf: &[u8],
|
buf: &[u8],
|
||||||
) -> Poll<std::io::Result<usize>> {
|
) -> Poll<std::io::Result<usize>> {
|
||||||
Pin::new(&mut self.get_mut().0).poll_write(cx, buf)
|
self.0.as_mut().poll_write(cx, buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll_write_vectored(
|
fn poll_write_vectored(
|
||||||
self: Pin<&mut Self>,
|
mut self: Pin<&mut Self>,
|
||||||
cx: &mut Context<'_>,
|
cx: &mut Context<'_>,
|
||||||
bufs: &[IoSlice<'_>],
|
bufs: &[IoSlice<'_>],
|
||||||
) -> Poll<std::io::Result<usize>> {
|
) -> Poll<std::io::Result<usize>> {
|
||||||
Pin::new(&mut self.get_mut().0).poll_write_vectored(cx, bufs)
|
self.0.as_mut().poll_write_vectored(cx, bufs)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
|
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
|
||||||
Pin::new(&mut self.get_mut().0).poll_flush(cx)
|
self.0.as_mut().poll_flush(cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
|
fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
|
||||||
Pin::new(&mut self.get_mut().0).poll_close(cx)
|
self.0.as_mut().poll_close(cx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user