You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
399 B
30 lines
399 B
|
|
|
|
pub struct RotatingList<T>(usize, Vec<T>);
|
|
|
|
impl<T> RotatingList<T>
|
|
{
|
|
pub fn new() -> Self {
|
|
Self(0, Vec::new())
|
|
}
|
|
|
|
pub fn push(&mut self, value: T)
|
|
{
|
|
self.1.push(value);
|
|
}
|
|
|
|
pub fn get(&mut self) -> &mut T
|
|
{
|
|
if self.0 >= self.1.len() {
|
|
self.0 = 0;
|
|
}
|
|
self.0 += 1;
|
|
|
|
&mut self.1[self.0-1]
|
|
}
|
|
|
|
pub fn iter(&mut self) -> &mut Vec<T> {
|
|
&mut self.1
|
|
}
|
|
}
|