[][src]Function qadapt::protection_level

pub fn protection_level() -> usize
Deprecated since 1.0.3:

Please use the alloc_counter crate instead.

Get the current "protection level" in QADAPT: calls to enter_protected() - exit_protected().

Note: For release builds, protection_level() will always return 0.

Example:

use qadapt::enter_protected;
use qadapt::exit_protected;
use qadapt::QADAPT;
use qadapt::protection_level;

#[global_allocator]
static Q: QADAPT = QADAPT;

fn main() {
    enter_protected();
    // We're now in an allocation-protected code region
    assert_eq!(1, protection_level());
     
    enter_protected();
    // We're still memory protected, but we'll now need to exit twice to be safe
    assert_eq!(2, protection_level());
    exit_protected();
    exit_protected();
     
    // It's now safe to allocate/drop
}