From 23a04b880fd678033611143c4b5d78fda57356f5 Mon Sep 17 00:00:00 2001 From: ZapAnton Date: Wed, 8 Aug 2018 00:32:32 +0300 Subject: [PATCH 1/2] circular-buffer: Added template to the stub file --- exercises/circular-buffer/src/lib.rs | 43 ++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/exercises/circular-buffer/src/lib.rs b/exercises/circular-buffer/src/lib.rs index 8b1378917..c655a5965 100644 --- a/exercises/circular-buffer/src/lib.rs +++ b/exercises/circular-buffer/src/lib.rs @@ -1 +1,44 @@ +use std::fmt::Debug; +use std::marker::PhantomData; +pub struct CircularBuffer { + // 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, +} + +#[derive(Debug, PartialEq)] +pub enum Error { + EmptyBuffer, + FullBuffer, +} + +impl CircularBuffer { + 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 element '{:?}' to the CircularBuffer or return FullBuffer error if CircularBuffer is full.", element); + } + + pub fn read(&mut self) -> Result { + 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 element '{:?}' to the CircularBuffer, overwriting the existing elements if CircularBuffer is full.", element); + } +} From 0f1a6baa1898f47c58dd15c0aaf1ea61e4a68f92 Mon Sep 17 00:00:00 2001 From: ZapAnton Date: Mon, 20 Aug 2018 09:26:04 +0300 Subject: [PATCH 2/2] circular-buffer: Removed the Debug trait bound from the stub file template --- exercises/circular-buffer/src/lib.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/exercises/circular-buffer/src/lib.rs b/exercises/circular-buffer/src/lib.rs index c655a5965..ed53f6ab7 100644 --- a/exercises/circular-buffer/src/lib.rs +++ b/exercises/circular-buffer/src/lib.rs @@ -1,7 +1,6 @@ -use std::fmt::Debug; use std::marker::PhantomData; -pub struct CircularBuffer { +pub struct CircularBuffer { // 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' @@ -15,7 +14,7 @@ pub enum Error { FullBuffer, } -impl CircularBuffer { +impl CircularBuffer { pub fn new(capacity: usize) -> Self { unimplemented!( "Construct a new CircularBuffer with the capacity to hold {}.", @@ -26,8 +25,8 @@ impl CircularBuffer { ); } - pub fn write(&mut self, element: T) -> Result<(), Error> { - unimplemented!("Write the element '{:?}' to the CircularBuffer or return FullBuffer error if CircularBuffer is full.", element); + 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 { @@ -38,7 +37,7 @@ impl CircularBuffer { unimplemented!("Clear the CircularBuffer."); } - pub fn overwrite(&mut self, element: T) { - unimplemented!("Write the element '{:?}' to the CircularBuffer, overwriting the existing elements if CircularBuffer is full.", element); + pub fn overwrite(&mut self, _element: T) { + unimplemented!("Write the passed element to the CircularBuffer, overwriting the existing elements if CircularBuffer is full."); } }