8
8
use {
9
9
crate :: println,
10
10
core:: {
11
- alloc:: { AllocError , AllocRef , Layout } ,
11
+ alloc:: { AllocError , Allocator , Layout } ,
12
12
cell:: Cell ,
13
13
ptr:: NonNull ,
14
14
} ,
@@ -20,9 +20,9 @@ pub struct BumpAllocator {
20
20
name : & ' static str ,
21
21
}
22
22
23
- unsafe impl AllocRef for BumpAllocator {
23
+ unsafe impl Allocator for BumpAllocator {
24
24
/// Allocate a memory block from the pool.
25
- fn alloc ( & self , layout : Layout ) -> Result < NonNull < [ u8 ] > , AllocError > {
25
+ fn allocate ( & self , layout : Layout ) -> Result < NonNull < [ u8 ] > , AllocError > {
26
26
let start = crate :: mm:: aligned_addr_unchecked ( self . next . get ( ) , layout. align ( ) ) ;
27
27
let end = start + layout. size ( ) ;
28
28
@@ -50,7 +50,7 @@ unsafe impl AllocRef for BumpAllocator {
50
50
}
51
51
52
52
/// A bump allocator doesn't care about releasing memory.
53
- unsafe fn dealloc ( & self , _ptr : NonNull < u8 > , _layout : Layout ) { }
53
+ unsafe fn deallocate ( & self , _ptr : NonNull < u8 > , _layout : Layout ) { }
54
54
}
55
55
56
56
impl BumpAllocator {
@@ -73,20 +73,20 @@ mod tests {
73
73
#[ test_case]
74
74
fn test_allocates_within_init_range ( ) {
75
75
let allocator = BumpAllocator :: new ( 256 , 512 , "Test allocator 1" ) ;
76
- let result1 = allocator. alloc ( unsafe { Layout :: from_size_align_unchecked ( 128 , 1 ) } ) ;
76
+ let result1 = allocator. allocate ( unsafe { Layout :: from_size_align_unchecked ( 128 , 1 ) } ) ;
77
77
assert ! ( result1. is_ok( ) ) ;
78
- let result2 = allocator. alloc ( unsafe { Layout :: from_size_align_unchecked ( 128 , 32 ) } ) ;
78
+ let result2 = allocator. allocate ( unsafe { Layout :: from_size_align_unchecked ( 128 , 32 ) } ) ;
79
79
println ! ( "{:?}" , result2) ;
80
80
assert ! ( result2. is_ok( ) ) ;
81
- let result3 = allocator. alloc ( unsafe { Layout :: from_size_align_unchecked ( 1 , 1 ) } ) ;
81
+ let result3 = allocator. allocate ( unsafe { Layout :: from_size_align_unchecked ( 1 , 1 ) } ) ;
82
82
assert ! ( result3. is_err( ) ) ;
83
83
}
84
84
// Creating with end <= start sshould fail
85
85
// @todo return Result<> from new?
86
86
#[ test_case]
87
87
fn test_bad_allocator ( ) {
88
88
let bad_allocator = BumpAllocator :: new ( 512 , 256 , "Test allocator 2" ) ;
89
- let result1 = bad_allocator. alloc ( unsafe { Layout :: from_size_align_unchecked ( 1 , 1 ) } ) ;
89
+ let result1 = bad_allocator. allocate ( unsafe { Layout :: from_size_align_unchecked ( 1 , 1 ) } ) ;
90
90
assert ! ( result1. is_err( ) ) ;
91
91
}
92
92
}
0 commit comments