pub struct EventStoreBuilder { /* private fields */ }Expand description
Builder for creating an EventStore with custom configuration.
The builder provides a fluent interface for configuring:
- Custom clock implementations (for testing or other purposes)
- Storage backends (for persistence)
- Time interval tracking (minutes, hours, days, weeks, months, years)
- Preset configurations (for rate limiting or analytics)
§Examples
use tiny_counter::EventStore;
let store = EventStore::builder()
.for_rate_limiting()
.build()
.unwrap();Implementations§
Source§impl EventStoreBuilder
impl EventStoreBuilder
Sourcepub fn with_clock(self, clock: Arc<dyn Clock>) -> Self
pub fn with_clock(self, clock: Arc<dyn Clock>) -> Self
Sets a custom clock implementation.
By default, SystemClock is used.
Accepts either a concrete Clock implementation or an Arc<dyn Clock>.
Sourcepub fn with_storage(self, storage: impl Storage + 'static) -> Self
pub fn with_storage(self, storage: impl Storage + 'static) -> Self
Sets a storage backend for persistence.
By default, no storage is configured.
Sourcepub fn with_format(self, formatter: impl Formatter + 'static) -> Self
pub fn with_format(self, formatter: impl Formatter + 'static) -> Self
Sets a serialization format for persistence.
By default, BincodeFormat is used if available.
Sourcepub fn track_seconds(self, count: usize) -> Self
pub fn track_seconds(self, count: usize) -> Self
Adds second-level tracking with the specified bucket count.
Sourcepub fn track_minutes(self, count: usize) -> Self
pub fn track_minutes(self, count: usize) -> Self
Adds minute-level tracking with the specified bucket count.
Sourcepub fn track_hours(self, count: usize) -> Self
pub fn track_hours(self, count: usize) -> Self
Adds hour-level tracking with the specified bucket count.
Sourcepub fn track_days(self, count: usize) -> Self
pub fn track_days(self, count: usize) -> Self
Adds day-level tracking with the specified bucket count.
Sourcepub fn track_weeks(self, count: usize) -> Self
pub fn track_weeks(self, count: usize) -> Self
Adds week-level tracking with the specified bucket count.
Sourcepub fn track_months(self, count: usize) -> Self
pub fn track_months(self, count: usize) -> Self
Adds month-level tracking with the specified bucket count.
Sourcepub fn track_years(self, count: usize) -> Self
pub fn track_years(self, count: usize) -> Self
Adds year-level tracking with the specified bucket count.
Sourcepub fn for_rate_limiting(self) -> Self
pub fn for_rate_limiting(self) -> Self
Configures the store for rate limiting use cases.
Tracks: 60 minutes, 72 hours (short-term tracking)
Sourcepub fn for_analytics(self) -> Self
pub fn for_analytics(self) -> Self
Configures the store for analytics use cases.
Tracks: 56 days, 52 weeks, 12 months (long-term tracking)
Sourcepub fn build(self) -> Result<EventStore>
pub fn build(self) -> Result<EventStore>
Builds the EventStore with the configured settings.
If auto_persist() was called with the tokio feature enabled,
a background task will be spawned to automatically persist dirty state.
§Errors
Returns an error if:
- Storage is configured but loading existing data fails
- Any bucket count is invalid
auto_persist()interval is not positive (zero or negative)auto_persist()is set but storage is not configured- Storage is configured but no formatter is available