1 unstable release

0.1.0 Sep 17, 2024

#230 in Memory management

Download history 116/week @ 2024-09-17 7/week @ 2024-09-24 6/week @ 2024-10-01

129 downloads per month

AGPL-3.0-or-later

3KB

allocdeny

Deny the use of crate alloc.

This crate exists solely to deny the use of the built-in alloc crate. This is useful if your library has different safety/soundness requirements than those allowed by Rust's own alloc.

Examples

The following code only compiles with this crate:

extern crate alloc;
alloc::allocdeny!();

When doing this, regular alloc is inaccessible.

Usage

Library authors who are doing their own thing and not relying on fn main() can simply expand this macro in their entry point wrapper. For example:

macro_rules! my_plugin {
  () => {
    alloc::allocdeny!();
    extern "C" fn plugin_init() {
    }
  }
}

Then users of my_plugin! will be unable to use alloc! You can also provide an unsafe version of my_plugin that does not expand alloc::allocdeny!(), if you want.


lib.rs:

allocdeny

Deny the use of crate alloc.

This crate exists solely to deny the use of the built-in alloc crate. This is useful if your library has different safety/soundness requirements than those allowed by Rust's own alloc.

Examples

The following code only compiles with this crate:

extern crate alloc;
alloc::allocdeny!();

When doing this, regular alloc is inaccessible.

Usage

Library authors who are doing their own thing and not relying on fn main() can simply expand this macro in their entry point wrapper. For example:

macro_rules! my_plugin {
  () => {
    alloc::allocdeny!();
    extern "C" fn plugin_init() {
    }
  }
}

Then users of my_plugin! will be unable to use alloc! You can also provide an unsafe version of my_plugin that does not expand alloc::allocdeny!(), if you want.

No runtime deps