Just as a motivating example, I am trying to convert a mildly complicated call from a Result to an associated IntoFuture type, to be compatible with tokio. This is not a very deep future stack, production applications will have much more complex combinators (you can see in the error output that the code being typed fits on 1 line). This is the kind of error I am getting because I wrote the annotation wrong:
Compiling cargonauts v0.1.1
error[E0308]: mismatched types
--> src/api/rel/fetch.rs:24:9
|
24 | <T as HasOne<Rel>>::has_one(entity).into_future().and_then(not_found).join(Ok(includes)).and_then(fetch_one)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected fn pointer, found fn item
|
= note: expected type `futures::AndThen<futures::Join<futures::AndThen<<<T as api::rel::HasOne<Rel>>::HasOneFut as futures::IntoFuture>::Future, std::result::Result<<<Rel as api::rel::Relation>::Resource as api::Resource>::Id, api::error::Error>, fn(std::option::Option<<<Rel as api::rel::Relation>::Resource as api::Resource>::Id>) -> std::result::Result<<<Rel as api::rel::Relation>::Resource as api::Resource>::Id, api::error::Error>>, futures::Done<std::vec::Vec<router::include::IncludeQuery>, api::error::Error>>, <<Rel as api::rel::Relation>::Resource as api::get::RawGet<I>>::IdFuture, fn((<<Rel as api::rel::Relation>::Resource as api::Resource>::Id, std::vec::Vec<router::include::IncludeQuery>)) -> <<Rel as api::rel::Relation>::Resource as api::get::RawGet<I>>::IdFuture>`
= note: found type `futures::AndThen<futures::Join<futures::AndThen<<<T as api::rel::HasOne<Rel>>::HasOneFut as futures::IntoFuture>::Future, std::result::Result<_, api::error::Error>, fn(std::option::Option<<<Rel as api::rel::Relation>::Resource as api::Resource>::Id>) -> std::result::Result<_, api::error::Error> {api::rel::fetch::not_found::<_>}>, futures::Done<std::vec::Vec<router::include::IncludeQuery>, api::error::Error>>, _, fn((_, std::vec::Vec<router::include::IncludeQuery>)) -> _ {api::rel::fetch::fetch_one::<_, _>}>`
error: aborting due to previous error
error: Could not compile `cargonauts`.
To learn more, run the command again with --verbose.
This is setting aside the fact that because I cannot express a closureās anonymous type in the associated type (AFAIK), I have to define helper functions and pass environment variables into the function explicitly using a join combinator.
@eddyb Doesnāt allowing impl trait in associated type positions push it even closer to some global inference? That associated type could appear in multiple positions in the function body, both input and output.