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 more instances of Unpin #403

Merged
merged 1 commit into from
Nov 7, 2020
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 src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,12 @@ pub mod tests {
use crate::error::{self, Error};
use crate::rpc;
use crate::{RequestId, Transport};
use futures::future;
use futures::future::{self, BoxFuture, FutureExt};
use std::cell::RefCell;
use std::collections::VecDeque;
use std::marker::Unpin;
use std::rc::Rc;

type Result<T> = Box<dyn futures::Future<Output = error::Result<T>> + Send + Unpin>;
type Result<T> = BoxFuture<'static, error::Result<T>>;

#[derive(Debug, Default, Clone)]
pub struct TestTransport {
Expand All @@ -123,13 +122,14 @@ pub mod tests {
}

fn send(&self, id: RequestId, request: rpc::Call) -> Result<rpc::Value> {
Box::new(future::ready(match self.responses.borrow_mut().pop_front() {
future::ready(match self.responses.borrow_mut().pop_front() {
Some(response) => Ok(response),
None => {
println!("Unexpected request (id: {:?}): {:?}", id, request);
Err(Error::Unreachable)
}
}))
})
.boxed()
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,14 @@ mod tests {
use super::{error, rpc, RequestId, Transport};

use crate::api::Web3;
use futures::Future;
use std::marker::Unpin;
use futures::future::BoxFuture;
use std::sync::Arc;

#[derive(Debug, Clone)]
struct FakeTransport;

impl Transport for FakeTransport {
type Out = Box<dyn Future<Output = error::Result<rpc::Value>> + Send + Unpin>;
type Out = BoxFuture<'static, error::Result<rpc::Value>>;

fn prepare(&self, _method: &str, _params: Vec<rpc::Value>) -> (RequestId, rpc::Call) {
unimplemented!()
Expand Down
7 changes: 5 additions & 2 deletions src/transports/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,13 @@ impl<T> Response<T> {
}
}

// We can do this because `hyper::client::ResponseFuture: Unpin`.
impl<T> Unpin for Response<T> {}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about T?

Copy link
Contributor Author

@e00E e00E Nov 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we trust the compiler then this must be okay because it does compile and there is no unsafe. I think this is because we never construct a Pin<T> so whether T is Unpin doesn't matter. Although I am not sure why the compiler doesn't automatically implement Unpin in this case.


impl<T, Out> Future for Response<T>
where
T: Fn(Vec<u8>) -> error::Result<Out> + Unpin,
Out: fmt::Debug + Unpin,
T: Fn(Vec<u8>) -> error::Result<Out>,
Out: fmt::Debug,
{
type Output = error::Result<Out>;

Expand Down