alloc_counter 0.0.4

Count allocations, reallocations, deallocations. Allow, deny, or forbid allocations on an expression or function basis.
#![cfg(feature = "macros")]

use alloc_counter::{no_alloc, AllocCounterSystem};
use futures_executor::block_on;

#[global_allocator]
static A: AllocCounterSystem = AllocCounterSystem;

#[test]
fn async_fn() {
    #[no_alloc]
    async fn foo() -> i32 {
        0
    }

    async fn bar() {
        foo().await;
    }

    block_on(bar());
}

#[test]
#[cfg_attr(debug_assertions, should_panic)]
fn async_fn_bad() {
    #[no_alloc]
    async fn foo() -> i32 {
        *Box::new(0)
    }

    async fn bar() {
        foo().await;
    }

    block_on(bar());
}