pub type HistoryBufView<T> = HistoryBufInner<T, ViewHistoryBufStorage<T>>;
Expand description
A “view” into a HistoryBuf
Unlike HistoryBuf
, it doesn’t have the const N: usize
in its type signature.
§Examples
use heapless::history_buf::{HistoryBuf, HistoryBufView};
// Initialize a new buffer with 8 elements.
let mut owned_buf = HistoryBuf::<_, 8>::new();
let buf: &mut HistoryBufView<_> = &mut owned_buf;
// Starts with no data
assert_eq!(buf.recent(), None);
buf.write(3);
buf.write(5);
buf.extend(&[4, 4]);
// The most recent written element is a four.
assert_eq!(buf.recent(), Some(&4));
// To access all elements in an unspecified order, use `as_slice()`.
for el in buf.as_slice() {
println!("{:?}", el);
}
// Now we can prepare an average of all values, which comes out to 4.
let avg = buf.as_slice().iter().sum::<usize>() / buf.len();
assert_eq!(avg, 4);
Aliased Type§
pub struct HistoryBufView<T> { /* private fields */ }