EventStoreBuilder

Struct EventStoreBuilder 

Source
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

Source

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>.

Source

pub fn with_storage(self, storage: impl Storage + 'static) -> Self

Sets a storage backend for persistence.

By default, no storage is configured.

Source

pub fn with_format(self, formatter: impl Formatter + 'static) -> Self

Sets a serialization format for persistence.

By default, BincodeFormat is used if available.

Source

pub fn track_seconds(self, count: usize) -> Self

Adds second-level tracking with the specified bucket count.

Source

pub fn track_minutes(self, count: usize) -> Self

Adds minute-level tracking with the specified bucket count.

Source

pub fn track_hours(self, count: usize) -> Self

Adds hour-level tracking with the specified bucket count.

Source

pub fn track_days(self, count: usize) -> Self

Adds day-level tracking with the specified bucket count.

Source

pub fn track_weeks(self, count: usize) -> Self

Adds week-level tracking with the specified bucket count.

Source

pub fn track_months(self, count: usize) -> Self

Adds month-level tracking with the specified bucket count.

Source

pub fn track_years(self, count: usize) -> Self

Adds year-level tracking with the specified bucket count.

Source

pub fn for_rate_limiting(self) -> Self

Configures the store for rate limiting use cases.

Tracks: 60 minutes, 72 hours (short-term tracking)

Source

pub fn for_analytics(self) -> Self

Configures the store for analytics use cases.

Tracks: 56 days, 52 weeks, 12 months (long-term tracking)

Source

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

Trait Implementations§

Source§

impl Default for EventStoreBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.