Add a FrameAllocator trait

This commit is contained in:
Philipp Oppermann
2015-11-14 19:21:23 +01:00
parent 75988f1324
commit 8304439c82
4 changed files with 29 additions and 9 deletions

View File

@@ -200,6 +200,16 @@ impl Frame {
}
```
We also add a `FrameAllocator` trait:
```rust
pub trait FrameAllocator {
fn allocate_frame(&mut self) -> Option<Frame>;
fn deallocate_frame(&mut self, frame: Frame);
}
```
This allows us to create another, more advanced frame allocator in the future.
### The Allocator
Now we can put everything together and create the frame allocator. It looks like this:
@@ -248,7 +258,7 @@ fn choose_next_area(&mut self) {
```
```rust
pub fn allocate_frame(&mut self) -> Option<Frame> {
fn allocate_frame(&mut self) -> Option<Frame> {
match self.current_area {
None => None,
Some(area) => {