Skip to content

Commit 5423243

Browse files
committed
Make CopyStream !Unpin
1 parent bccfa83 commit 5423243

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

tokio-postgres/src/copy_out.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::client::{InnerClient, Responses};
2+
use pin_project_lite::pin_project;
23
use crate::codec::FrontendMessage;
34
use crate::connection::RequestMessages;
45
use crate::types::ToSql;
@@ -8,6 +9,7 @@ use futures::{ready, Stream};
89
use postgres_protocol::message::backend::Message;
910
use std::pin::Pin;
1011
use std::task::{Context, Poll};
12+
use std::marker::PhantomPinned;
1113

1214
pub async fn copy_out<'a, I>(
1315
client: &InnerClient,
@@ -20,7 +22,7 @@ where
2022
{
2123
let buf = query::encode(client, &statement, params)?;
2224
let responses = start(client, buf).await?;
23-
Ok(CopyStream { responses })
25+
Ok(CopyStream { responses, _p: PhantomPinned })
2426
}
2527

2628
async fn start(client: &InnerClient, buf: Bytes) -> Result<Responses, Error> {
@@ -39,16 +41,22 @@ async fn start(client: &InnerClient, buf: Bytes) -> Result<Responses, Error> {
3941
Ok(responses)
4042
}
4143

42-
/// A stream of `COPY ... TO STDOUT` query data.
43-
pub struct CopyStream {
44-
responses: Responses,
44+
pin_project! {
45+
/// A stream of `COPY ... TO STDOUT` query data.
46+
pub struct CopyStream {
47+
responses: Responses,
48+
#[pin]
49+
_p: PhantomPinned,
50+
}
4551
}
4652

4753
impl Stream for CopyStream {
4854
type Item = Result<Bytes, Error>;
4955

50-
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
51-
match ready!(self.responses.poll_next(cx)?) {
56+
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
57+
let this = self.project();
58+
59+
match ready!(this.responses.poll_next(cx)?) {
5260
Message::CopyData(body) => Poll::Ready(Some(Ok(body.into_bytes()))),
5361
Message::CopyDone => Poll::Ready(None),
5462
_ => Poll::Ready(Some(Err(Error::unexpected_message()))),

0 commit comments

Comments
 (0)