@@ -35,37 +35,55 @@ impl<const N: usize> Chonk<N> {
3535 }
3636}
3737
38- pub struct OwnedHeap < F > {
38+ pub struct Dropper < const N : usize > {
39+ putter : * mut Chonk < N > ,
40+ }
41+
42+ impl < const N : usize > Dropper < N > {
43+ fn new ( putter : * mut Chonk < N > ) -> Self {
44+ Self { putter }
45+ }
46+ }
47+
48+ impl < const N : usize > Drop for Dropper < N > {
49+ fn drop ( & mut self ) {
50+ unsafe { Chonk :: unleak ( self . putter ) }
51+ }
52+ }
53+
54+ pub struct OwnedHeap < const N : usize > {
3955 heap : Heap ,
40- _drop : F ,
56+ _drop : Dropper < N > ,
4157}
4258
43- impl < F > Deref for OwnedHeap < F > {
59+ impl < const N : usize > Deref for OwnedHeap < N > {
4460 type Target = Heap ;
4561
4662 fn deref ( & self ) -> & Self :: Target {
4763 & self . heap
4864 }
4965}
5066
51- impl < F > DerefMut for OwnedHeap < F > {
67+ impl < const N : usize > DerefMut for OwnedHeap < N > {
5268 fn deref_mut ( & mut self ) -> & mut Self :: Target {
5369 & mut self . heap
5470 }
5571}
5672
57- pub fn new_heap ( ) -> OwnedHeap < impl Sized > {
73+ pub fn new_heap ( ) -> OwnedHeap < 1000 > {
5874 const HEAP_SIZE : usize = 1000 ;
5975 let ( heap_space_ptr, data_ptr) = Chonk :: < HEAP_SIZE > :: new ( ) ;
6076
6177 let heap = unsafe { Heap :: new ( data_ptr, HEAP_SIZE ) } ;
6278 assert_eq ! ( heap. bottom( ) , data_ptr) ;
6379 assert_eq ! ( heap. size( ) , align_down_size( HEAP_SIZE , size_of:: <usize >( ) ) ) ;
64- let drop = move || unsafe { Chonk :: unleak ( heap_space_ptr) } ;
65- OwnedHeap { heap, _drop : drop }
80+ OwnedHeap {
81+ heap,
82+ _drop : Dropper :: new ( heap_space_ptr) ,
83+ }
6684}
6785
68- fn new_max_heap ( ) -> OwnedHeap < impl Sized > {
86+ fn new_max_heap ( ) -> OwnedHeap < 2048 > {
6987 const HEAP_SIZE : usize = 1024 ;
7088 const HEAP_SIZE_MAX : usize = 2048 ;
7189 let ( heap_space_ptr, data_ptr) = Chonk :: < HEAP_SIZE_MAX > :: new ( ) ;
@@ -75,18 +93,21 @@ fn new_max_heap() -> OwnedHeap<impl Sized> {
7593 assert_eq ! ( heap. bottom( ) , data_ptr) ;
7694 assert_eq ! ( heap. size( ) , HEAP_SIZE ) ;
7795
78- let drop = move || unsafe { Chonk :: unleak ( heap_space_ptr) } ;
79- OwnedHeap { heap, _drop : drop }
96+ OwnedHeap {
97+ heap,
98+ _drop : Dropper :: new ( heap_space_ptr) ,
99+ }
80100}
81101
82- fn new_heap_skip ( ct : usize ) -> OwnedHeap < impl Sized > {
102+ fn new_heap_skip ( ct : usize ) -> OwnedHeap < 1000 > {
83103 const HEAP_SIZE : usize = 1000 ;
84104 let ( heap_space_ptr, data_ptr) = Chonk :: < HEAP_SIZE > :: new ( ) ;
85105
86106 let heap = unsafe { Heap :: new ( data_ptr. add ( ct) , HEAP_SIZE - ct) } ;
87-
88- let drop = move || unsafe { Chonk :: unleak ( heap_space_ptr) } ;
89- OwnedHeap { heap, _drop : drop }
107+ OwnedHeap {
108+ heap,
109+ _drop : Dropper :: new ( heap_space_ptr) ,
110+ }
90111}
91112
92113#[ test]
0 commit comments