1 unstable release
0.1.0 | Jan 23, 2024 |
---|
#570 in Memory management
4KB
dummy-alloc
Provides DummyAlloc
, a global allocator that fails all allocations.
lib.rs
:
Provides DummyAlloc
, a global allocator that fails all allocations.
Example
use std::alloc::{alloc, Layout};
use dummy_alloc::DummyAlloc;
// Configure it as the global allocator.
#[global_allocator]
static GLOBAL: DummyAlloc = DummyAlloc;
let layout = Layout::new::<i32>();
let ptr = unsafe { alloc(layout) };
// `DummyAlloc` always returns a null pointer on allocation.
assert!(ptr.is_null());
Minimum supported Rust version
The MSRV is currently 1.56.
This may change between minor versions.
License
I release this crate into the public domain using the Unlicense.
Similar crates
lol_alloc
exports a similar
FailAllocator
that performs the same function.