alloc/lib.rs
1//! # allocdeny
2//!
3//! Deny the use of crate `alloc`.
4//!
5//! This crate exists solely to deny the use of the built-in `alloc` crate.
6//! This is useful if your library has different safety/soundness requirements
7//! than those allowed by Rust's own `alloc`.
8//!
9//! # Examples
10//!
11//! The following code only compiles with this crate:
12//!
13//! ```rust
14//! extern crate alloc;
15//! alloc::allocdeny!();
16//! ```
17//!
18//! When doing this, regular alloc is inaccessible.
19//!
20//! # Usage
21//!
22//! Library authors who are doing their own thing and not relying on fn main()
23//! can simply expand this macro in their entry point wrapper. For example:
24//!
25//! ```rust
26//! macro_rules! my_plugin {
27//! () => {
28//! alloc::allocdeny!();
29//! extern "C" fn plugin_init() {
30//! }
31//! }
32//! }
33//! ```
34//!
35//! Then users of `my_plugin!` will be unable to use `alloc`!
36//! You can also provide an `unsafe` version of `my_plugin` that does not expand
37//! `alloc::allocdeny!()`, if you want.
38
39#[macro_export]
40macro_rules! allocdeny {
41 () => { alloc::allocdenied!(); }
42}
43
44#[macro_export]
45macro_rules! allocdenied {
46 () => { }
47}