1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//! This crate provides a utility for counting updates, for instance frame rates.
//!
//! Implementors of the `RateCounter` trait have a
//! method, `.update()`, which is meant to be called every time your system
//! updates (e.g. every frame, every physics update, etc).
//!
//! The trait `RateCounterImmut` adds an immutable update method which consumes
//! the rate counter and returns an updated one.
//!
//! This can also be done immutably using shadowing and `.update_immut()`.
//!
//! # Examples
//! The one important thing to remember is to call your Counter's `update()`
//! (or `update_immut()`) at the beginning of your cycles.
//!
//! ```
//! use update_rate::{RateCounter, DiscreteRateCounter};
//! // Create a new DiscreteRateCounter with a sample rate of 10 updates
//! let mut c = DiscreteRateCounter::new(10);
//!
//! for _ in 1..11 {
//! c.update();
//! // Rate should be 100 Hz with 10 ms/update
//! std::thread::sleep(std::time::Duration::from_millis(10));
//! }
//!
//! let difference = 100.0 - c.rate();
//! println!("Rate was {}", c.rate());
//! assert!(difference < 10.0, "Counter rate should be closer to actual rate.");
//! ```
pub use DiscreteRateCounter;
pub use RollingRateCounter;
pub use *;
/// Basic rate counter functionality.
///
/// Types which implement RateCounter also implement Display (a string with "<cycles> Hz") and Debug (including samples as well).
/// Immutable extensions for rate counters.