2023-12-14 23:38:27 -06:00
|
|
|
#![feature(coverage_attribute)]
|
|
|
|
#![feature(noop_waker)]
|
2024-02-22 06:10:29 -06:00
|
|
|
//@ edition: 2018
|
2021-04-18 17:04:59 -05:00
|
|
|
|
|
|
|
fn non_async_func() {
|
|
|
|
println!("non_async_func was covered");
|
|
|
|
let b = true;
|
|
|
|
if b {
|
|
|
|
println!("non_async_func println in block");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn async_func() {
|
|
|
|
println!("async_func was covered");
|
|
|
|
let b = true;
|
|
|
|
if b {
|
|
|
|
println!("async_func println in block");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn async_func_just_println() {
|
|
|
|
println!("async_func_just_println was covered");
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
println!("codecovsample::main");
|
|
|
|
|
|
|
|
non_async_func();
|
|
|
|
|
|
|
|
executor::block_on(async_func());
|
|
|
|
executor::block_on(async_func_just_println());
|
|
|
|
}
|
|
|
|
|
|
|
|
mod executor {
|
2023-12-14 23:38:27 -06:00
|
|
|
use core::future::Future;
|
|
|
|
use core::pin::pin;
|
|
|
|
use core::task::{Context, Poll, Waker};
|
2021-04-18 17:04:59 -05:00
|
|
|
|
2023-12-14 23:38:27 -06:00
|
|
|
#[coverage(off)]
|
2021-04-18 17:04:59 -05:00
|
|
|
pub fn block_on<F: Future>(mut future: F) -> F::Output {
|
2023-12-14 23:38:27 -06:00
|
|
|
let mut future = pin!(future);
|
2024-01-14 18:25:43 -06:00
|
|
|
let mut context = Context::from_waker(Waker::noop());
|
2021-04-18 17:04:59 -05:00
|
|
|
|
|
|
|
loop {
|
|
|
|
if let Poll::Ready(val) = future.as_mut().poll(&mut context) {
|
|
|
|
break val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|