Skip to content

0.3: How can I return a Future from a trait function? #1058

Closed
@ngg

Description

@ngg

With 0.1.x and 0.2.x it was possible to return Box<Future<Item = ..., Error = ...>>, but with the 0.3 branch it's no longer possible.

trait T {
    fn f() -> Box<Future<Output = ()>>;
}

This code gives the following compile error:

error[E0038]: the trait `std::future::Future` cannot be made into an object
 --> src/main.rs:4:5
  |
4 |     fn f() -> Box<Future<Output = ()>>;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::future::Future` cannot be made into an object
  |
  = note: method `poll` has a non-standard `self` type

Returning with impl Trait is not allowed in trait functions, so that method does not work on any branch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions