Rust 如何在Tokio';什么是水槽?

Rust 如何在Tokio';什么是水槽?,rust,future,rust-tokio,Rust,Future,Rust Tokio,我想创建一个方法,在实现Tokio的结构上发送一些数据,但是我在使用Pin作为self时遇到了问题。本质上,我需要这样的东西: fn send_data(&mut self, data: Item, cx: &mut Context) -> Poll<Result<(), Error>> { futures_core::ready!(something.poll_ready(cx))?; something.start_send(da

我想创建一个方法,在实现Tokio的结构上发送一些数据,但是我在使用
Pin
作为self时遇到了问题。本质上,我需要这样的东西:

fn send_data(&mut self, data: Item, cx: &mut Context) -> Poll<Result<(), Error>> {
    futures_core::ready!(something.poll_ready(cx))?;
    something.start_send(data)?;
    futures_core::ready!(something.poll_close(cx))
}

看起来你的问题可能会由你的答案来回答。如果没有,请回答您的问题以解释差异。否则,我们可以将此问题标记为已回答。为什么不使用
self:Pin
而不是
&mut self
?这将问题向上传播,但我成功地解决了它(还不确定它为什么起作用,需要稍微消化一下):看起来您的问题可能由的答案来回答。如果没有,请回答您的问题以解释差异。否则,我们可以将此问题标记为已回答。您为什么不使用
self:Pin
而不是
&mut self
?这将问题向上传播,但我设法解决了它(还不确定它为什么有效,需要稍微消化一下):
use futures_core;
use std::pin::Pin;
use tokio::prelude::*; // 0.3.0-alpha.1

struct Test {}

impl Sink<i32> for Test {
    type Error = ();

    fn poll_ready(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
        Poll::Ready(Ok(()))
    }

    fn start_send(self: Pin<&mut Self>, item: i32) -> Result<(), Self::Error> {
        Ok(())
    }

    fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
        Poll::Ready(Ok(()))
    }

    fn poll_close(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
        Poll::Ready(Ok(()))
    }
}

impl Test {
    fn send_data(&mut self, data: i32, cx: &mut Context) -> Poll<Result<(), Error>> {
        // what should "something" here be?
        futures_core::ready!(something.poll_ready(cx))?;
        something.start_send(data)?;
        futures_core::ready!(something.poll_close(cx))
    }
}