Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions exercises/circular-buffer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,43 @@
use std::marker::PhantomData;

pub struct CircularBuffer<T> {
// This field is here to make the template compile and not to
// complain about unused type parameter 'T'. Once you start
// solving the exercise, delete this field and the 'std::marker::PhantomData'
// import.
field: PhantomData<T>,
}

#[derive(Debug, PartialEq)]
pub enum Error {
EmptyBuffer,
FullBuffer,
}

impl<T> CircularBuffer<T> {
pub fn new(capacity: usize) -> Self {
unimplemented!(
"Construct a new CircularBuffer with the capacity to hold {}.",
match capacity {
1 => format!("1 element"),
_ => format!("{} elements", capacity),
}
);
}

pub fn write(&mut self, _element: T) -> Result<(), Error> {
unimplemented!("Write the passed element to the CircularBuffer or return FullBuffer error if CircularBuffer is full.");
}

pub fn read(&mut self) -> Result<T, Error> {
unimplemented!("Read the oldest element from the CircularBuffer or return EmptyBuffer error if CircularBuffer is empty.");
}

pub fn clear(&mut self) {
unimplemented!("Clear the CircularBuffer.");
}

pub fn overwrite(&mut self, _element: T) {
unimplemented!("Write the passed element to the CircularBuffer, overwriting the existing elements if CircularBuffer is full.");
}
}