Skip to content

Commit e4f6e7d

Browse files
authored
Merge pull request #13 from imbolc/master
Add support for async main
2 parents 225560c + ef8013c commit e4f6e7d

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/manifest.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ pub fn split_input(
5252
let (manifest, source) =
5353
find_embedded_manifest(content).unwrap_or((Manifest::Toml(""), content));
5454

55-
let source = if source.lines().any(|line| line.starts_with("fn main()")) {
55+
let source = if source
56+
.lines()
57+
.any(|line| line.starts_with("fn main()") || line.starts_with("async fn main()"))
58+
{
5659
source.to_string()
5760
} else {
5861
format!("fn main() -> Result<(), Box<dyn std::error::Error+Sync+Send>> {{\n {{\n {} }}\n Ok(())\n}}", source)

tests/data/script-async-main.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//! This is merged into a default manifest in order to form the full package manifest:
2+
//!
3+
//! ```cargo
4+
//! [dependencies]
5+
//! boolinator = "=0.1.0"
6+
//! tokio = { version = "1", features = ["full"] }
7+
//! ```
8+
use boolinator::Boolinator;
9+
10+
#[tokio::main]
11+
async fn main() {
12+
println!("--output--");
13+
println!("{:?}", true.as_some(1));
14+
}

tests/tests/script.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,12 @@ fn script_without_main_question_mark() {
152152
.stderr
153153
.starts_with("Error: Os { code: 2, kind: NotFound, message:"));
154154
}
155+
156+
#[test]
157+
fn test_script_async_main() {
158+
let out = rust_script!("tests/data/script-async-main.rs").unwrap();
159+
scan!(out.stdout_output();
160+
("Some(1)") => ()
161+
)
162+
.unwrap()
163+
}

0 commit comments

Comments
 (0)