Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support peek_many and pop_many #12

Merged
merged 10 commits into from
Dec 16, 2023
Prev Previous commit
Next Next commit
fix: typos and clippy warnings
  • Loading branch information
lulf committed Dec 15, 2023
commit 0564a9e5c67e34b9c8538f5420188570cd985913
21 changes: 9 additions & 12 deletions src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,7 @@ pub fn push<S: NorFlash>(
/// If you also want to remove the data use [pop_many].
///
/// Returns an iterator-like type that can be used to peek into the data.
pub fn peek_many<'d, S: NorFlash>(
flash: &'d mut S,
flash_range: Range<u32>,
) -> PeekIterator<'d, S> {
pub fn peek_many<S: NorFlash>(flash: &mut S, flash_range: Range<u32>) -> PeekIterator<'_, S> {
PeekIterator {
iter: QueueIterator::new(flash, flash_range),
}
Expand Down Expand Up @@ -198,10 +195,10 @@ pub fn peek<'d, S: NorFlash>(
/// If you don't want to remove the data use [peek_many].
///
/// Returns an iterator-like type that can be used to pop the data.
pub fn pop_many<'d, S: MultiwriteNorFlash>(
flash: &'d mut S,
pub fn pop_many<S: MultiwriteNorFlash>(
flash: &mut S,
flash_range: Range<u32>,
) -> PopIterator<'d, S> {
) -> PopIterator<'_, S> {
PopIterator {
iter: QueueIterator::new(flash, flash_range),
}
Expand Down Expand Up @@ -280,7 +277,7 @@ impl<'d, S: NorFlash> PeekIterator<'d, S> {
}
}

/// An iterator-like interface for peeking into events stored in flash.
/// An iterator-like interface for peeking into data stored in flash.
struct QueueIterator<'d, S: NorFlash> {
flash: &'d mut S,
flash_range: Range<u32>,
Expand Down Expand Up @@ -604,11 +601,11 @@ mod tests {
);
}

let mut poper = pop_many(&mut flash, flash_range.clone());
let mut popper = pop_many(&mut flash, flash_range.clone());
for i in 0..5 {
let data = vec![i as u8; 50];
assert_eq!(
&poper.next(&mut data_buffer).unwrap().unwrap()[..],
&popper.next(&mut data_buffer).unwrap().unwrap()[..],
&data,
"At {i}"
);
Expand All @@ -629,11 +626,11 @@ mod tests {
);
}

let mut poper = pop_many(&mut flash, flash_range.clone());
let mut popper = pop_many(&mut flash, flash_range.clone());
for i in 5..25 {
let data = vec![i as u8; 50];
assert_eq!(
&poper.next(&mut data_buffer).unwrap().unwrap()[..],
&popper.next(&mut data_buffer).unwrap().unwrap()[..],
&data,
"At {i}"
);
Expand Down