Scott Conger
Scott Conger

Reputation: 130

Define a trait with FnOnce, but no return type

I'd like to define a trait like so (to avoid repetition later):

trait Callback: FnOnce() + Send {}

However, the compiler demands that I define Output from FnOnce:

error: the value of the associated type Output (from the trait core::ops::FnOnce) must be specified [E0191]

I tried to default the value, but it warns that this is unstable.

type Output = ();

error: associated type defaults are unstable

What can I define Output as to indicate "No return"? The normal function call syntax simply omits it.

Upvotes: 3

Views: 695

Answers (1)

DK.
DK.

Reputation: 58975

You can fix this by being explicit about the return type:

trait Callback: FnOnce() -> () + Send {}

I'm honestly not sure if this is a bug or not.

Upvotes: 5

Related Questions