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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
//! Track event counts across multiple time windows with fixed memory and fast queries.
//!
//! This library solves the problem of tracking events (like user actions, API calls, or system
//! events) when you need to answer questions like "how many times did this happen in the last
//! week?" without storing every individual timestamp.
//!
//! # Key Features
//!
//! - **Fixed memory**: Each event uses ~2KB regardless of event count
//! - **Multiple time windows**: Query at different granularities (minutes, hours, days, weeks, months, years)
//! - **Fast queries**: All queries run in O(buckets) time, independent of event count
//! - **Persistence**: Save to SQLite, JSON, or custom storage backends
//! - **Merge-friendly**: Combine event data from multiple sources for distributed systems
//!
//! # Quick Start
//!
//! ```
//! use tiny_counter::EventStore;
//! use chrono::Duration;
//!
//! let mut store = EventStore::new();
//!
//! // Record events
//! store.record("app_launch");
//! store.record("app_launch");
//!
//! // Query last 7 days
//! let launches = store
//! .query("app_launch")
//! .last_days(7)
//! .sum()
//! .unwrap_or(0);
//!
//! assert_eq!(launches, 2);
//! ```
//!
//! # Recording Events
//!
//! Record events that just happened:
//!
//! ```
//! # use tiny_counter::EventStore;
//! let mut store = EventStore::new();
//! store.record("button_click");
//! store.record_count("api_call", 5);
//! ```
//!
//! Record events from the past:
//!
//! ```
//! # use tiny_counter::EventStore;
//! # use chrono::{Duration, Utc};
//! let mut store = EventStore::new();
//! let timestamp = Utc::now() - Duration::days(2);
//! store.record_at("feature_used", timestamp).unwrap();
//! store.record_ago("sync", Duration::hours(3));
//! ```
//!
//! # Querying Events
//!
//! Query event counts across different time ranges:
//!
//! ```
//! # use tiny_counter::EventStore;
//! let mut store = EventStore::new();
//! store.record("app_launch");
//!
//! // Different time granularities
//! let last_hour = store.query("app_launch").last_minutes(60).sum().unwrap();
//! let last_day = store.query("app_launch").last_hours(24).sum().unwrap();
//! let last_week = store.query("app_launch").last_days(7).sum().unwrap();
//! ```
//!
//! # Rate Limiting
//!
//! Enforce rate limits with multiple constraints:
//!
//! ```
//! # use tiny_counter::{EventStore, TimeUnit};
//! let mut store = EventStore::new();
//!
//! let result = store
//! .limit()
//! .at_most("api_call", 10, TimeUnit::Minutes)
//! .at_most("api_call", 100, TimeUnit::Hours)
//! .check_and_record("api_call");
//!
//! assert!(result.is_ok());
//! ```
//!
//! # Persistence
//!
//! Save and load event data (requires `serde` feature with a storage backend like `storage-fs`):
//!
//!
pub use Formatter;
pub use ;
pub use ;
pub use EventStoreBuilder;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
/// Internal APIs exposed for benchmarking only.
///
/// **WARNING:** These APIs have no stability guarantees and may change
/// or be removed without notice. Do not use in production code.
///
/// This module exists to support performance benchmarking while clearly
/// signaling that these are internal implementation details.
// Internal re-exports for crate use
pub use CountRing;
pub use EventCounterConfig;
pub use SingleEventCounter;
pub use IntervalConfig;
pub use IntervalCounter;
pub use EventStoreInner;