| Crates.io | running_buffer |
| lib.rs | running_buffer |
| version | 0.1.1 |
| created_at | 2025-05-26 11:39:14.173341+00 |
| updated_at | 2025-06-06 13:49:40.613523+00 |
| description | data types for keeping track of changing values, allowing analysis in trends and histories. |
| homepage | https://codeberg.org/aidavdw/running_buffer.rs |
| repository | https://codeberg.org/aidavdw/running_buffer.rs |
| max_upload_size | |
| id | 1689433 |
| size | 16,090 |
Data types for variables of which you want to monitor their changing state.
a History keeps track of how a value changes over time.
Its focus is on giving the ability to compare recent history with longer-duration history.
It saves N_MOST_RECENT values, and in addition keeps cumulative and total amount of all previous value as well.
This way both recent and total historical values can be assessed and compared.
let mut s = History::<u32, u64, 2>::new();
assert_eq!(s.most_recent(), None);
assert_eq!(s.total_tests, 0);
assert_eq!(s.total_historic, 0);
s.push(100);
assert_eq!(s.most_recent().unwrap(), &100);
assert_eq!(s.total_tests, 1);
assert_eq!(s.total_historic, 100);
s.push(101);
assert_eq!(s.most_recent().unwrap(), &101);
assert_eq!(s.previous().unwrap(), &100);
assert_eq!(s.total_tests, 2);
assert_eq!(s.total_historic, 201);
// Only keeps 2 most recent, other only as cumulative.
s.push(102);
assert_eq!(s.most_recent().unwrap(), &102);
assert_eq!(s.previous().unwrap(), &101);
assert_eq!(s.n_ago(2), None);
assert_eq!(s.total_tests, 3);
assert_eq!(s.total_historic, 303);
CUM type.As keeping a very long history might run out of bounds of the variable type T, a separate type CUM is used to store long-term cumulative data.
The only requirement is for T to be transformable into CUM.
For example, I want to record instances of u32. If I record history.pushed(4_294_967_200).pushed(500000), u32 would overflow.
By taking the CUM type as u64, you can keep the size of the History smaller than if you were to store all instances as u64, while still having an accurate cumulative number.