mirror of
https://github.com/bspeice/qadapt
synced 2024-11-24 06:48:09 -05:00
Add an async demonstration
This commit is contained in:
parent
26ebd50fc0
commit
9e5b2b0f7a
@ -24,3 +24,6 @@ spin = { git = "https://github.com/bspeice/spin-rs.git" }
|
||||
thread-id = "3.3"
|
||||
|
||||
qadapt-macro = { version = "0.7.1", path = "./qadapt-macro" }
|
||||
|
||||
[dev-dependencies]
|
||||
futures = "0.1"
|
||||
|
33
tests/async.rs
Normal file
33
tests/async.rs
Normal file
@ -0,0 +1,33 @@
|
||||
use futures::future::ok;
|
||||
use futures::prelude::*;
|
||||
use qadapt::assert_no_alloc;
|
||||
use qadapt::no_alloc;
|
||||
use qadapt::QADAPT;
|
||||
|
||||
#[global_allocator]
|
||||
static Q: QADAPT = QADAPT;
|
||||
|
||||
#[no_alloc]
|
||||
fn async_box() -> impl Future<Item = Box<u8>, Error = ()> {
|
||||
ok(12).and_then(|e| Ok(Box::new(e)))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raw_call() {
|
||||
async_box();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn guarded_call() {
|
||||
assert_no_alloc!(async_box());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn guarded_poll() {
|
||||
if cfg!(debug_assertions) {
|
||||
assert_no_alloc!(async_box().poll().unwrap());
|
||||
} else {
|
||||
panic!("Intentional")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user