mirror of
https://github.com/rust-embedded/heapless.git
synced 2025-09-26 20:10:24 +00:00
Simplify implementation of ordered_get
.
This commit is contained in:
parent
2f0008b4ca
commit
a795502288
@ -527,16 +527,7 @@ impl<T, S: HistBufStorage<T> + ?Sized> HistoryBufferInner<T, S> {
|
||||
/// assert_eq!(buffer.ordered_get(6), None);
|
||||
/// ```
|
||||
pub fn ordered_get(&self, idx: usize) -> Option<&T> {
|
||||
if self.len() <= idx {
|
||||
None
|
||||
} else {
|
||||
let (front, back) = self.as_slices();
|
||||
if idx < front.len() {
|
||||
Some(&front[idx])
|
||||
} else {
|
||||
Some(&back[idx - front.len()])
|
||||
}
|
||||
}
|
||||
self.oldest_ordered().nth(idx)
|
||||
}
|
||||
|
||||
/// Returns double ended iterator for iterating over the buffer from
|
||||
|
Loading…
x
Reference in New Issue
Block a user