Skip to content

Commit cf03a53

Browse files
committed
Add const empty() function
1 parent bd337ac commit cf03a53

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/hole.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ pub struct HoleList {
1414
}
1515

1616
impl HoleList {
17+
pub const fn empty() -> HoleList {
18+
HoleList {
19+
first: Hole {
20+
size: 0,
21+
next: None,
22+
},
23+
}
24+
}
25+
1726
pub unsafe fn new(ptr: *mut Hole, size: usize) -> HoleList {
1827
assert!(size_of::<Hole>() == Self::min_size());
1928

src/lib.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![feature(unique)]
2+
#![feature(const_fn)]
23
#![no_std]
34

45
#[cfg(test)]
@@ -16,6 +17,14 @@ pub struct Heap {
1617
}
1718

1819
impl Heap {
20+
pub const fn empty() -> Heap {
21+
Heap {
22+
top: 0,
23+
bottom: 0,
24+
holes: HoleList::empty(),
25+
}
26+
}
27+
1928
pub fn new(heap_bottom: usize, heap_top: usize) -> Heap {
2029
Heap {
2130
bottom: heap_bottom,
@@ -38,11 +47,11 @@ impl Heap {
3847
}
3948
self.holes.deallocate(ptr, size);
4049
}
41-
50+
4251
pub fn bottom(&self) -> usize {
4352
self.bottom
4453
}
45-
54+
4655
pub fn top(&self) -> usize {
4756
self.top
4857
}

0 commit comments

Comments
 (0)