#Return a future with output that is of Option?
24 messages · Page 1 of 1 (latest)
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?
Ya, its just this
async fn get_account() -> Future<Output = Option<Account>> {
debug!("COMMAND#get_account invoked");
async {
Some(Account::empty())
}
}
ah you don't use an async block inside an async fn
ohhh
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
(that means putting edition = "2021" in your Cargo.toml and fixing any errors that come up; https://doc.rust-lang.org/edition-guide/rust-2021/index.html has the migration info)
I am, that error was from IntelliJ intellisense
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 {}
}
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`.
↑ that's the error you should be getting from that syntax
Well even with cargo check your Output = Option<Account> still doesnt compile