-
Notifications
You must be signed in to change notification settings - Fork 631
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
Compat
implementation
#1119
Compat
implementation
#1119
Conversation
impl<Fut, T> Future for NeverError<Fut> | ||
where Fut: Future<Output = T>, | ||
{ | ||
type Output = Result<T, ()>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know that Never
was introduced only in 0.2 when I proposed the name NeverError
. I think we should come up with another name for this type. Maybe UnitError
?
That said, I continue to believe that this combinator is useful. .map(|x| Ok::<_, ()>(x))
would be damn annoying to type.
type Output = Result<T, ()>; | ||
|
||
fn poll(mut self: PinMut<Self>, cx: &mut task::Context) -> Poll<Result<T, ()>> { | ||
match self.future().poll(cx) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.future().poll(cx).map(|x| Ok(x))
is shorter :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or even .map(Ok)
😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
futures-util/src/future/mod.rs
Outdated
@@ -83,6 +86,8 @@ if_std! { | |||
|
|||
mod shared; | |||
pub use self::shared::Shared; | |||
|
|||
use std::boxed::PinBox; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Best placed right underneath if_std! {
. We usually have the imports on top
futures-util/src/compat/executor.rs
Outdated
|
||
pub trait ExecCompat: Executor01< | ||
Compat<FutureObj<'static, ()>, BoxedExecutor> | ||
> + Clone + Send + 'static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub trait ExecCompat: Executor01<Fut> + Clone + Send + 'static
where Fut: Compat<FutureObj<'static, ()>, BoxedExecutor>
{
The multiline <...>
reminds me of C++ xD
Edit: Meh we would need to create this type param... Ignore that then (I tested it, but it compiled because this file was never mentioned in a mod
statement)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you rename the trait to Executor01CompatExt
?
futures-util/src/compat/executor.rs
Outdated
} | ||
|
||
#[derive(Clone)] | ||
pub struct ExecutorCompat<E> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to CompatExecutor
futures-util/src/compat/executor.rs
Outdated
impl<E> Executor03 for ExecutorCompat<E> | ||
where E: Executor01< | ||
Compat<FutureObj<'static, ()>, Box<Executor03>> | ||
>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fits on single line (or if you prefer to split it use a type param)
futures-util/Cargo.toml
Outdated
@@ -29,6 +30,7 @@ futures-io-preview = { path = "../futures-io", version = "0.3.0-alpha.1", defaul | |||
futures-sink-preview = { path = "../futures-sink", version = "0.3.0-alpha.1", default-features = false} | |||
either = { version = "1.4", default-features = false } | |||
slab = { version = "0.4", optional = true } | |||
futures = { version = "0.1", optional = true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m surprised this plus the dev-dependency below don’t cause issues for the tests (both have a lib name of futures
). Again here’s a place where having crate renaming for the edition would be super useful to make this futures01
or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, it does:
→ cargo test --features compat --manifest-path futures-util/Cargo.toml
Downloading futures v0.1.23
Compiling futures v0.1.23
Compiling futures-util-preview v0.3.0-alpha.1 (file:///home/wim/sources/github.com/Nemo157/futures-rs/futures-util)
Compiling futures-executor-preview v0.3.0-alpha.1 (file:///home/wim/sources/github.com/Nemo157/futures-rs/futures-executor)
Compiling futures-preview v0.3.0-alpha.1 (file:///home/wim/sources/github.com/Nemo157/futures-rs/futures)
Finished dev [unoptimized + debuginfo] target(s) in 13.43s
Running target/debug/deps/futures_util-0b0ee17c1f6f37a3
running 1 test
test sink::fanout::tests::it_works ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Doc-tests futures_util
error[E0465]: multiple rlib candidates for `futures` found
--> /home/wim/sources/github.com/Nemo157/futures-rs/futures-util/src/compat/mod.rs:6:5
|
6 | use futures::Future as Future01;
| ^^^^^^^
|
note: candidate #1: /home/wim/sources/github.com/Nemo157/futures-rs/target/debug/deps/libfutures-e0fcc61a6ffa167e.rlib
--> /home/wim/sources/github.com/Nemo157/futures-rs/futures-util/src/compat/mod.rs:6:5
|
6 | use futures::Future as Future01;
| ^^^^^^^
note: candidate #2: /home/wim/sources/github.com/Nemo157/futures-rs/target/debug/deps/libfutures-6ebec9b92185abd2.rlib
--> /home/wim/sources/github.com/Nemo157/futures-rs/futures-util/src/compat/mod.rs:6:5
|
6 | use futures::Future as Future01;
| ^^^^^^^
error[E0463]: can't find crate for `futures`
--> /home/wim/sources/github.com/Nemo157/futures-rs/futures-util/src/compat/mod.rs:6:5
|
6 | use futures::Future as Future01;
| ^^^^^^^ can't find crate
And unfortunately renaming dependencies has issues that block it being used for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should convene the council of elders
One temporary solution could be to fully rename our libraries to futures-preview
. Long term though, we'll need crate renaming because both crates will share a name in the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we get away with moving Compat
into its own futures-compat
sub crate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that'll work for now, since it doesn't need to import the 0.3 futures
facade it won't run into the name conflict. Once renaming is working then it could be merged back into futures-util
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, testing with a locally built cargo
including rust-lang/cargo#5794 using futures01 = { version = "0.1", optional = true, package = "futures" }
(and adjusting all the use
s) appears to run the tests fine. (EDIT: here's the commit I tested with)
So, if you're willing to wait for a new cargo
to be released to nightly that's one option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what the Cargo release cycle is like, my current nightly toolchain has rustc
from 2018-07-23 but cargo
from 2018-07-17, so I don't think it's always the latest master.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this pr requires a new nightly anyway for the Executor stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tinaun Wouldn't the newtype approach be more lightweight?
futures-util/src/compat/executor.rs
Outdated
>, | ||
E: Clone + Send + 'static, | ||
{ | ||
fn spawn_obj(&mut self, obj: FutureObj<'static, ()>) -> Result<(), task::SpawnObjError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long line
fn spawn_obj(
&mut self,
future: FutureObj<'static, ()>,
) -> Result<(), task::SpawnObjError> {
Note: Trailing comma, renamed obj
to future
(This is the thing that I and Aaron want to call future, currently it is called "task")
futures-util/src/compat/mod.rs
Outdated
|
||
use core::mem::PinMut; | ||
use core::marker::Unpin; | ||
use std::sync::Arc; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use std
instead of core
(we do that elsewhere as well)
futures-util/src/compat/mod.rs
Outdated
use core::mem::PinMut; | ||
use core::marker::Unpin; | ||
use std::sync::Arc; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mod executor;
pub use self::executor::*;
(But list individual exports instead of *
)
@tinaun Brilliant work! ATM it doesn't compile because the
|
@tinaun are you planning on working on adaptors for |
@tinaun I think your approach to pack everything related to compatibility into Additionally to the stuff you mentioned above, |
Since I need them for a project I want to use as a test case for this I've got |
besides the NeverError bikeshed and the cargo renamings this should be about done |
0b78491
to
8bdff6b
Compare
IMO the cargo renaming can wait. This compiles and works currently, we just can’t run the tests with the feature active until renaming is supported. |
I'm going to merge this now. We still need need to document it (I think Big thanks to @tinaun ! |
Guess that means I should get onto doing the rebase of my changes I'd planned 😄 |
futures-util/src/compat/executor.rs
Outdated
let fut = exec_err.into_future().into_inner().unwrap_or_else(|_| ()); | ||
SpawnObjError { | ||
kind: SpawnErrorKind::shutdown(), | ||
task: Box::new(fut).into(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This field is now future
.
based on @MajorBreakfast's approach here rustasync/team#26 (comment)
issues:
where should 0.1 -> 0.3 combinators live?