composable_allocators/
non_working.rs

1use crate::base::*;
2use const_default_derive::ConstDefault;
3use core::alloc::{self, AllocError, Allocator};
4use core::hint::unreachable_unchecked;
5use core::ptr::NonNull;
6
7#[derive(Debug, Copy, Clone, ConstDefault)]
8pub struct NonWorking;
9
10unsafe impl NonUnwinding for NonWorking { }
11
12unsafe impl Fallbackable for NonWorking {
13    unsafe fn has_allocated(&self, _ptr: NonNull<u8>, _layout: alloc::Layout) -> bool {
14        false
15    }
16
17    fn allows_fallback(&self, _layout: alloc::Layout) -> bool {
18        true
19    }
20}
21
22unsafe impl Allocator for NonWorking {
23    fn allocate(&self, _layout: alloc::Layout) -> Result<NonNull<[u8]>, AllocError> {
24        Err(AllocError)
25    }
26
27    fn allocate_zeroed(&self, _layout: alloc::Layout) -> Result<NonNull<[u8]>, AllocError> {
28        Err(AllocError)
29    }
30
31    unsafe fn deallocate(&self, _ptr: NonNull<u8>, _layout: alloc::Layout) {
32        unreachable_unchecked()
33    }
34
35    unsafe fn grow(
36        &self, 
37        _ptr: NonNull<u8>, 
38        _old_layout: alloc::Layout, 
39        _new_layout: alloc::Layout
40    ) -> Result<NonNull<[u8]>, AllocError> {
41        Err(AllocError)
42    }
43
44    unsafe fn grow_zeroed(
45        &self, 
46        _ptr: NonNull<u8>, 
47        _old_layout: alloc::Layout, 
48        _new_layout: alloc::Layout
49    ) -> Result<NonNull<[u8]>, AllocError> {
50        Err(AllocError)
51    }
52
53    unsafe fn shrink(
54        &self, 
55        _ptr: NonNull<u8>, 
56        _old_layout: alloc::Layout, 
57        _new_layout: alloc::Layout
58    ) -> Result<NonNull<[u8]>, AllocError> {
59        Err(AllocError)
60    }
61}