Skip to content

Commit cfdb2c6

Browse files
authored
Merge pull request #44 from tweedegolf/combine-pop-and-peek
Only use deref for entry
2 parents 3906f90 + ec66a77 commit cfdb2c6

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/queue.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ pub async fn peek<'d, S: NorFlash>(
227227
let next_value = iterator.next(data_buffer).await?;
228228

229229
match next_value {
230-
Some(entry) => Ok(Some(entry.into_data())),
230+
Some(entry) => Ok(Some(entry.into_buf())),
231231
None => Ok(None),
232232
}
233233
}
@@ -464,20 +464,16 @@ impl<'s, 'd, 'q, S: NorFlash, CI: CacheImpl> Deref for QueueIteratorEntry<'s, 'd
464464
}
465465
}
466466

467-
impl<'s, 'd, 'q, S: NorFlash, CI: CacheImpl> QueueIteratorEntry<'s, 'd, 'q, S, CI> {
468-
/// Get a mutable reference to the data of this entry
469-
pub fn data_mut(&mut self) -> &mut [u8] {
467+
impl<'s, 'd, 'q, S: NorFlash, CI: CacheImpl> DerefMut for QueueIteratorEntry<'s, 'd, 'q, S, CI> {
468+
fn deref_mut(&mut self) -> &mut Self::Target {
470469
self.item.data_mut()
471470
}
471+
}
472472

473-
/// Get a reference to the data of this entry
474-
pub fn data(&self) -> &[u8] {
475-
self.item.data()
476-
}
477-
473+
impl<'s, 'd, 'q, S: NorFlash, CI: CacheImpl> QueueIteratorEntry<'s, 'd, 'q, S, CI> {
478474
/// Get a mutable reference to the data of this entry, but consume the entry too.
479-
/// This function has some relaxed lifetime constraints compared to [Self::data_mut].
480-
pub fn into_data(self) -> &'d mut [u8] {
475+
/// This function has some relaxed lifetime constraints compared to the deref impls.
476+
pub fn into_buf(self) -> &'d mut [u8] {
481477
let (header, data) = self.item.destruct();
482478
&mut data[..header.length as usize]
483479
}
@@ -987,7 +983,7 @@ mod tests {
987983
.await
988984
.unwrap()
989985
.unwrap()
990-
.data(),
986+
.deref(),
991987
&data[..],
992988
"At {i}"
993989
);
@@ -1043,7 +1039,7 @@ mod tests {
10431039
.await
10441040
.unwrap()
10451041
.unwrap()
1046-
.data(),
1042+
.deref(),
10471043
&data,
10481044
"At {i}"
10491045
);

0 commit comments

Comments
 (0)