-
Notifications
You must be signed in to change notification settings - Fork 0
/
reef.rs
52 lines (40 loc) · 1.08 KB
/
reef.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use crate::prey::Prey;
// VecDeque is Rust's implementation of a double-ended queue, and
// is used only if we only need to use it in a single-ended manner.
use std::collections::vec_deque::{Iter, VecDeque};
#[derive(Debug)]
pub struct Reef {
prey: VecDeque<Box<dyn Prey>>,
}
impl Reef {
pub fn new() -> Self {
// unimplemented!();
Reef { prey: VecDeque::new() }
}
pub fn prey(&self) -> Iter<Box<dyn Prey>> {
// unimplemented!();
self.prey.iter()
}
pub fn population(&self) -> usize {
// unimplemented!();
self.prey.len()
}
/**
* Adds a prey to the reef.
*
* This function takes ownership of the boxed prey.
*/
pub fn add_prey(&mut self, prey: Box<dyn Prey>) {
// unimplemented!();
self.prey.push_back(prey);
}
/**
* Returns the next available prey.
*
* The callee of this function receives ownership of the boxed prey.
*/
pub fn take_prey(&mut self) -> Option<Box<dyn Prey>> {
// unimplemented!();
self.prey.pop_front()
}
}