about summary refs log tree commit diff
path: root/tests/ui/async-await/async-closures/clone-closure.rs
blob: 807897e3e03146fd8ee7fbb9a3d149bd0a2bcc89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//@ aux-build:block-on.rs
//@ edition:2021
//@ run-pass
//@ check-run-results

#![feature(async_closure)]

extern crate block_on;

async fn for_each(f: impl async FnOnce(&str) + Clone) {
    f.clone()("world").await;
    f.clone()("world2").await;
}

fn main() {
    block_on::block_on(async_main());
}

async fn async_main() {
    let x = String::from("Hello,");
    for_each(async move |s| {
        println!("{x} {s}");
    }).await;
}