Difference between async block and async fn

this basic tokio example, I got error
the trait bound fn() -> impl std::future::Future {hello}: std::future::Future is not satisfied: the trait std::future::Future is not implemented for fn() -> impl std::future::Future {hello}

however, rt.block_on(async { println!("Hello"); }); works. Why? what's the difference? Thanks.

use tokio::runtime::Runtime;
use tokio::prelude::*;

  fn main() {
    let mut rt = Runtime::new().unwrap();
    rt.block_on(hello);
   // This works
   // rt.block_on(async { println!("Hello"); });
  }
  async fn hello() {
    println!("hello");
  }

in Cargo.toml

[dependencies]
tokio = { version = "0.2",  features = ["rt-core", "tcp", "macros", "dns", "io-util"] }

async fn is a function, so you should call it to get future.

rt.block_on(hello());

Thanks, :+1:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.