Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Unpin requirements from get_pin_mut #1820

Merged
merged 1 commit into from Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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