#Return a future with output that is of Option?

24 messages · Page 1 of 1 (latest)

dire cave
#

I am writing an async function that is meant to return an Option<Account>. I get the following error though and dont know what to make of it
the trait bound 'dyn Future<Output=Option<Account>>: std::marker::Sized' is not satisfied [E0277] 'dyn Future<Output=Option<Account>>' does not have a constant size known at compile-time

stable plinth
#

that error does not mean that you're doing anything wrong with Option

#

it means that you're trying to do something with dyn Future that you can't (regardless of what its output type is)

#

can you show your code and the full error message from cargo check, please?

dire cave
#

Ya, its just this

async fn get_account() -> Future<Output = Option<Account>> {
    debug!("COMMAND#get_account invoked");
    async {
        Some(Account::empty())
    }
}
stable plinth
#

ah you don't use an async block inside an async fn

dire cave
#

ohhh

stable plinth
#

just

async fn get_account() -> Output = Option<Account> {
    debug!("COMMAND#get_account invoked");
    Some(Account::empty())
}
#

also the fact that that code was allowed means that you are on an old language edition; you should update that when you have spare time and are not in the middle of changing something else

dire cave
#

I am, that error was from IntelliJ intellisense

stable plinth
#

ah

#

IMO, do not trust IntelliJ

#

they reimplemented large parts of Rust syntax/semantics, and got things wrong

#

like, I'm not saying you should switch to a different IDE

#

but any time you get an error you don't fully understand, you must consult cargo check to see if it's real

#

?play

use std::future::Future;
async fn get_account() -> Future<Output = ()> {
    async {}
}
feral sequoiaBOT
#
error[E0782]: trait objects must include the `dyn` keyword
 --> src/main.rs:3:27
  |
3 | async fn get_account() -> Future<Output = ()> {
  |                           ^^^^^^^^^^^^^^^^^^^
  |
help: add `dyn` keyword before this trait
  |
3 | async fn get_account() -> dyn Future<Output = ()> {
  |                           +++

For more information about this error, try `rustc --explain E0782`.
stable plinth
#

↑ that's the error you should be getting from that syntax

dire cave
#

Well even with cargo check your Output = Option<Account> still doesnt compile

stable plinth
#

oh sorry

#

I was deleting text and did not delete enough

#

I meant:

#
async fn get_account() -> Option<Account> {
    debug!("COMMAND#get_account invoked");
    Some(Account::empty())
}