1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//! Provides [`DummyAllocator`], a global allocator that fails all allocations.
//!
//! # Example
//!
//! ```no_run
//! use std::alloc::{alloc, Layout};
//! use dummy_alloc::DummyAllocator;
//!
//! // Configure it as the global allocator.
//! #[global_allocator]
//! static GLOBAL: DummyAllocator = DummyAllocator;
//!
//! let layout = Layout::new::<i32>();
//! let ptr = unsafe { alloc(layout) };
//! // `DummyAllocator` always returns a null pointer on allocation.
//! assert!(ptr.is_null());
//! ```
//!
//! # Similar crates
//!
//! [`lol_alloc`](https://crates.io/crates/lol_alloc) exports a similar
//! `FailAllocator` that performs the same function.
//!
//! # Minimum supported Rust version
//!
//! The MSRV is currently 1.56.
//!
//! This may change between minor versions.
//!
//! # License
//!
//! This crate is licensed under the
//! [Blue Oak Model License 1.0.0](https://blueoakcouncil.org/license/1.0.0).
// Attributes
// Lints
extern crate alloc;
use ;
/// A dummy allocator.
///
/// Allocation will always fail by returning a null pointer. Deallocation will
/// always do nothing.
///
/// # Example
///
/// You may use it as the global allocator like so:
///
/// ```no_run
/// use dummy_alloc::DummyAllocator;
///
/// #[global_allocator]
/// static GLOBAL: DummyAllocator = DummyAllocator;
/// ```
///
/// See the [`alloc`](alloc::alloc) documentation for more information.
;
// SAFETY: Does not unwind and does not rely on allocation occurring.
unsafe