Skip to content

Commit

Permalink
test into iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
jdonszelmann committed Jun 8, 2023
1 parent e5aa09c commit 10d70dd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
27 changes: 27 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,33 @@ mod tests {
test_iter(ConstGenericRingBuffer::<i32, 8>::new());
}

#[test]
fn run_test_into_iter() {
fn test_iter(mut b: impl RingBufferExt<i32>) {
b.push(1);
b.push(2);
b.push(3);
b.push(4);
b.push(5);
b.push(6);
b.push(7);

let mut iter = b.into_iter();
assert_eq!(1, iter.next().unwrap());
assert_eq!(2, iter.next().unwrap());
assert_eq!(3, iter.next().unwrap());
assert_eq!(4, iter.next().unwrap());
assert_eq!(5, iter.next().unwrap());
assert_eq!(6, iter.next().unwrap());
assert_eq!(7, iter.next().unwrap());
assert_eq!(None, iter.next());
}

test_iter(AllocRingBuffer::new(8));
test_iter(GrowableAllocRingBuffer::with_capacity(8));
test_iter(ConstGenericRingBuffer::<i32, 8>::new());
}

#[cfg(feature = "alloc")]
#[test]
fn run_test_iter_with_lifetimes() {
Expand Down
4 changes: 2 additions & 2 deletions src/ringbuffer_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ mod iter {
phantom: PhantomData<T>,
}

impl<T, RB: RingBufferRead<T>> RingBufferIntoIterator<T, RB> {
impl<T, RB: RingBufferExt<T>> RingBufferIntoIterator<T, RB> {
#[inline]
pub fn new(obj: RB) -> Self {
Self {
Expand All @@ -398,7 +398,7 @@ mod iter {
}
}

impl<T, RB: RingBufferRead<T>> Iterator for RingBufferIntoIterator<T, RB> {
impl<T, RB: RingBufferExt<T>> Iterator for RingBufferIntoIterator<T, RB> {
type Item = T;

fn next(&mut self) -> Option<Self::Item> {
Expand Down

1 comment on commit 10d70dd

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please # to comment.