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
use crate::base::*;
use const_default_derive::ConstDefault;
use core::alloc::{self, AllocError, Allocator};
use core::hint::unreachable_unchecked;
use core::ptr::NonNull;

#[derive(Debug, Copy, Clone, ConstDefault)]
pub struct NonWorking;

unsafe impl NonUnwinding for NonWorking { }

unsafe impl Fallbackable for NonWorking {
    unsafe fn has_allocated(&self, _ptr: NonNull<u8>, _layout: alloc::Layout) -> bool {
        false
    }

    fn allows_fallback(&self, _layout: alloc::Layout) -> bool {
        true
    }
}

unsafe impl Allocator for NonWorking {
    fn allocate(&self, _layout: alloc::Layout) -> Result<NonNull<[u8]>, AllocError> {
        Err(AllocError)
    }

    fn allocate_zeroed(&self, _layout: alloc::Layout) -> Result<NonNull<[u8]>, AllocError> {
        Err(AllocError)
    }

    unsafe fn deallocate(&self, _ptr: NonNull<u8>, _layout: alloc::Layout) {
        unreachable_unchecked()
    }

    unsafe fn grow(
        &self, 
        _ptr: NonNull<u8>, 
        _old_layout: alloc::Layout, 
        _new_layout: alloc::Layout
    ) -> Result<NonNull<[u8]>, AllocError> {
        Err(AllocError)
    }

    unsafe fn grow_zeroed(
        &self, 
        _ptr: NonNull<u8>, 
        _old_layout: alloc::Layout, 
        _new_layout: alloc::Layout
    ) -> Result<NonNull<[u8]>, AllocError> {
        Err(AllocError)
    }

    unsafe fn shrink(
        &self, 
        _ptr: NonNull<u8>, 
        _old_layout: alloc::Layout, 
        _new_layout: alloc::Layout
    ) -> Result<NonNull<[u8]>, AllocError> {
        Err(AllocError)
    }
}