Skip to content

Commit

Permalink
Remove Unpin requirements from get_pin_mut
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Aug 23, 2019
1 parent cde791c commit 30928c7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
10 changes: 5 additions & 5 deletions futures-util/src/sink/fanout.rs
Expand Up @@ -33,11 +33,11 @@ impl<Si1, Si2> Fanout<Si1, Si2> {
}

/// Get a pinned mutable reference to the inner sinks.
pub fn get_pin_mut(self: Pin<&mut Self>) -> (Pin<&mut Si1>, Pin<&mut Si2>)
where Si1: Unpin, Si2: Unpin,
{
let Self { sink1, sink2 } = self.get_mut();
(Pin::new(sink1), Pin::new(sink2))
pub fn get_pin_mut(self: Pin<&mut Self>) -> (Pin<&mut Si1>, Pin<&mut Si2>) {
unsafe {
let Self { sink1, sink2 } = self.get_unchecked_mut();
(Pin::new_unchecked(sink1), Pin::new_unchecked(sink2))
}
}

/// Consumes this combinator, returning the underlying sinks.
Expand Down
5 changes: 4 additions & 1 deletion futures-util/src/stream/into_future.rs
Expand Up @@ -3,6 +3,7 @@ use core::pin::Pin;
use futures_core::future::{FusedFuture, Future};
use futures_core::stream::Stream;
use futures_core::task::{Context, Poll};
use pin_utils::unsafe_pinned;

/// Future for the [`into_future`](super::StreamExt::into_future) method.
#[derive(Debug)]
Expand All @@ -14,6 +15,8 @@ pub struct StreamFuture<St> {
impl<St: Stream + Unpin> Unpin for StreamFuture<St> {}

impl<St: Stream + Unpin> StreamFuture<St> {
unsafe_pinned!(stream: Option<St>);

pub(super) fn new(stream: St) -> StreamFuture<St> {
StreamFuture { stream: Some(stream) }
}
Expand Down Expand Up @@ -54,7 +57,7 @@ impl<St: Stream + Unpin> StreamFuture<St> {
/// in order to return it to the caller of `Future::poll` if the stream yielded
/// an element.
pub fn get_pin_mut(self: Pin<&mut Self>) -> Option<Pin<&mut St>> {
Pin::new(&mut self.get_mut().stream).as_pin_mut()
self.stream().as_pin_mut()
}

/// Consumes this combinator, returning the underlying stream.
Expand Down
10 changes: 5 additions & 5 deletions futures-util/src/stream/select.rs
Expand Up @@ -56,11 +56,11 @@ impl<St1, St2> Select<St1, St2> {
///
/// Note that care must be taken to avoid tampering with the state of the
/// stream which may otherwise confuse this combinator.
pub fn get_pin_mut(self: Pin<&mut Self>) -> (Pin<&mut St1>, Pin<&mut St2>)
where St1: Unpin, St2: Unpin,
{
let Self { stream1, stream2, .. } = self.get_mut();
(Pin::new(stream1.get_mut()), Pin::new(stream2.get_mut()))
pub fn get_pin_mut(self: Pin<&mut Self>) -> (Pin<&mut St1>, Pin<&mut St2>) {
unsafe {
let Self { stream1, stream2, .. } = self.get_unchecked_mut();
(Pin::new_unchecked(stream1).get_pin_mut(), Pin::new_unchecked(stream2).get_pin_mut())
}
}

/// Consumes this combinator, returning the underlying streams.
Expand Down
10 changes: 5 additions & 5 deletions futures-util/src/stream/zip.rs
Expand Up @@ -58,11 +58,11 @@ impl<St1: Stream, St2: Stream> Zip<St1, St2> {
///
/// Note that care must be taken to avoid tampering with the state of the
/// stream which may otherwise confuse this combinator.
pub fn get_pin_mut(self: Pin<&mut Self>) -> (Pin<&mut St1>, Pin<&mut St2>)
where St1: Unpin, St2: Unpin,
{
let Self { stream1, stream2, .. } = self.get_mut();
(Pin::new(stream1.get_mut()), Pin::new(stream2.get_mut()))
pub fn get_pin_mut(self: Pin<&mut Self>) -> (Pin<&mut St1>, Pin<&mut St2>) {
unsafe {
let Self { stream1, stream2, .. } = self.get_unchecked_mut();
(Pin::new_unchecked(stream1).get_pin_mut(), Pin::new_unchecked(stream2).get_pin_mut())
}
}

/// Consumes this combinator, returning the underlying streams.
Expand Down

0 comments on commit 30928c7

Please sign in to comment.