{"id":307,"hash":"dc0ddc00b6b593025aa1de26bdb40946ef575af76ff63771c7664b5e14063050","pattern":"Cannot find tokio::main macro?","full_message":"I am creating a sample Rust project in my Windows system to download a file by HTTP GET request in async mode.\n\nMy code is as follows (same as the code mentioned in the Rust Cookbook):\n\nextern crate error_chain;\nextern crate tempfile;\nextern crate tokio;\nextern crate reqwest;\n\nuse error_chain::error_chain;\nuse std::io::copy;\nuse std::fs::File;\nuse tempfile::Builder;\n\nerror_chain! {\n     foreign_links {\n         Io(std::io::Error);\n         HttpRequest(reqwest::Error);\n     }\n}\n\n#[tokio::main]\nasync fn main() -> Result<()> {\n    let tmp_dir = Builder::new().prefix(\"example\").tempdir()?;\n    let target = \"https://www.rust-lang.org/logos/rust-logo-512x512.png\";\n    let response = reqwest::get(target).await?;\n\n    let mut dest = {\n        let fname = response\n            .url()\n            .path_segments()\n            .and_then(|segments| segments.last())\n            .and_then(|name| if name.is_empty() { None } else { Some(name) })\n            .unwrap_or(\"tmp.bin\");\n\n        println!(\"file to download: '{}'\", fname);\n        let fname = tmp_dir.path().join(fname);\n        println!(\"will be located under: '{:?}'\", fname);\n        File::create(fname)?\n    };\n    let content =  response.text().await?;\n    copy(&mut content.as_bytes(), &mut dest)?;\n    Ok(())\n}\n\nMy Cargo.toml file is:\n\n[package]\nname = \"abcdef\"\nversion = \"0.1.0\"\nauthors = [\"xyz\"]\nedition = \"2018\"\n\n# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html\n\n[dependencies]\nerror-chain = \"0.12.4\"\ntempfile = \"3.1.0\"\ntokio = \"0.2.22\"\nreqwest = \"0.10.8\"\n\nWhen I execute cargo run, the following errors are displayed:\n\nerror[E0433]: failed to resolve: could not find `main` in `tokio`\n  --> src\\main.rs:18:10\n   |\n18 | #[tokio::main]\n   |          ^^^^ could not find `main` in `tokio`\n\nerror[E0277]: `main` has invalid return type `impl std::future::Future`\n  --> src\\main.rs:19:20\n   |\n19 | async fn main() -> Result<()> {\n   |                    ^^^^^^^^^^ `main` can only return types that implement `\nstd::process::Termination`\n   |\n   = help: consider using `()`, or a `Result`\n\nerror[E0752]: `main` function is not allowed to be `async`\n  --> src\\main.rs:19:1\n   |\n19 | async fn main() -> Result<()> {\n   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `main` function is not allowed to be `async`\n\nI cross-checked from the Cargo.toml file & edition = \"2018\" was already there. I am unable to figure out the other errors.","ecosystem":"cargo","package_name":"async-await","package_version":null,"solution":"You need to enable an extra feature in tokio to be able to use tokio::main.\n\nTry adding the full feature to the tokio dependency in your Cargo.toml file:\n\n[dependencies]\ntokio = { version = \"0.2.22\", features = [\"full\"] }\n\nThis also applies to later versions of Tokio.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/63874178/cannot-find-tokiomain-macro","votes":62,"created_at":"2026-04-19T04:41:50.435168+00:00","updated_at":"2026-04-19T04:52:30.364782+00:00"}