Skip to content

Commit

Permalink
Address review comments on names and doc
Browse files Browse the repository at this point in the history
  • Loading branch information
HeroicKatora committed Oct 16, 2021
1 parent 855b651 commit fd82f6f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,11 @@ impl Heap {
}
}

/// Crates a new heap from a slice of raw memory.
pub fn with_memory(mem: &'static mut [MaybeUninit<u8>]) -> Heap {
/// Creates a new heap from a slice of raw memory.
///
/// This has the same effect as [`init_from_slice`] on an empty heap, but it is combined into a
/// single operation that can not panic.
pub fn from_slice(mem: &'static mut [MaybeUninit<u8>]) -> Heap {
let size = mem.len();
let address = mem.as_ptr() as usize;
// SAFETY: The given address and size is valid according to the safety invariants of the
Expand Down
8 changes: 4 additions & 4 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn new_heap() -> Heap {
let heap_space = Box::leak(Box::new([MaybeUninit::uninit(); HEAP_SIZE]));
let assumed_location = heap_space.as_ptr() as usize;

let heap = Heap::with_memory(heap_space);
let heap = Heap::from_slice(heap_space);
assert!(heap.bottom == assumed_location);
assert!(heap.size == HEAP_SIZE);
heap
Expand All @@ -18,11 +18,11 @@ fn new_max_heap() -> Heap {
const HEAP_SIZE: usize = 1024;
const HEAP_SIZE_MAX: usize = 2048;
let heap_space = Box::leak(Box::new([MaybeUninit::<u8>::uninit(); HEAP_SIZE_MAX]));
let assumed_location = heap_space.as_ptr() as usize;
let start_ptr = heap_space.as_ptr() as usize;

// Unsafe so that we have provenance over the whole allocation.
let heap = unsafe { Heap::new(assumed_location, HEAP_SIZE) };
assert!(heap.bottom == assumed_location);
let heap = unsafe { Heap::new(start_ptr, HEAP_SIZE) };
assert!(heap.bottom == start_ptr);
assert!(heap.size == HEAP_SIZE);
heap
}
Expand Down

0 comments on commit fd82f6f

Please sign in to comment.