eppo_core/lib.rs
1//! `eppo_core` is a common library to build Eppo SDKs for different languages. If you're an Eppo
2//! user, you probably want to take a look at one of the existing SDKs.
3//!
4//! # Overview
5//!
6//! `eppo_core` is organized as a set of building blocks that help to build Eppo SDKs. Different
7//! languages have different constraints. Some languages might use all building blocks and others
8//! might reimplement some pieces in the host language.
9//!
10//! [`Configuration`] is the heart of an SDK. It is an immutable structure that encapsulates all
11//! server-provided configuration ([flag configurations](ufc::UniversalFlagConfig) and [bandit
12//! models](bandits::BanditResponse)) that describes how the SDK should evaluate user requests.
13//!
14//! [`ConfigurationStore`](configuration_store::ConfigurationStore) is a thread-safe multi-reader
15//! multi-writer in-memory manager for [`Configuration`]. The job of configuration store is to be a
16//! central authority on what configuration is currently active. Whenever configuration changes, it
17//! is replaced completely. When a reader gets a configuration, it receives a *snapshot* that is not
18//! affected by further writes—to provide a consistent response to user, it is important that
19//! reader uses the same `Configuration` snapshot throughout the operation.
20//!
21//! [`ConfigurationFetcher`](configuration_fetcher::ConfigurationFetcher) is an HTTP client that
22//! knows how to fetch [`Configuration`] from the server. It's best to save and reuse the same
23//! instance, so it can reuse the connection.
24//!
25//! [`PollerThread`](poller_thread::PollerThread) launches a background thread that periodically
26//! fetches a new `Configuration` (using `ConfigurationFetcher`) and updates
27//! `ConfigurationStore`. This is the simplest way to keep the SDK configuration up-to-date.
28//!
29//! [`eval`] module contains functions for flag and bandit evaluation. It also supports evaluation
30//! with [details](eval::eval_details::EvaluationDetails). These functions return evaluation results
31//! along with [`events`]—they do not log events automatically.
32//!
33//! [`events`] module contains definitions of [`AssignmentEvent`](events::AssignmentEvent) and
34//! [`BanditEvent`](events::BanditEvent) that need to be submitted to user's analytics storage for
35//! further analysis. `eppo_core` does not provide an "assignment logger" abstraction yet as
36//! callback handling is currently too different between languages (e.g., in Ruby, it's too tedious
37//! to call from Rust into Ruby, so we return events into Ruby land where they get logged).
38//!
39//! Because evaluation functions are pure functions (they don't have side effects and don't use any
40//! global state), they are a bit tedious to call directly. [`Evaluator`](eval::Evaluator) is a
41//! helper to simplify SDK code and pass repeated parameters automatically.
42//!
43//! Most SDKs are built from a `ConfigurationStore`, a `PollerThread`, and an `Evaluator`.
44//!
45//! # Versioning
46//!
47//! This library follows semver. However, it is considered an internal library, so expect frequent
48//! breaking changes and major version bumps.
49
50#![warn(rustdoc::missing_crate_level_docs)]
51
52// Re-export public dependencies.
53#[cfg(feature = "ahash")]
54pub use ahash;
55
56pub mod attributes;
57pub mod background;
58pub mod bandits;
59pub mod configuration_fetcher;
60pub mod configuration_poller;
61pub mod configuration_store;
62pub mod eval;
63#[cfg(feature = "event_ingestion")]
64pub mod event_ingestion;
65pub mod events;
66#[cfg(feature = "pyo3")]
67pub mod pyo3;
68pub mod sharder;
69pub mod timestamp;
70pub mod ufc;
71
72mod configuration;
73mod error;
74mod hashmap;
75mod obfuscation;
76mod precomputed;
77mod sdk_key;
78mod sdk_metadata;
79mod str;
80
81pub use crate::str::Str;
82pub use attributes::{
83 AttributeValue, Attributes, CategoricalAttribute, ContextAttributes, NumericAttribute,
84};
85pub use configuration::Configuration;
86pub use error::{Error, EvaluationError, Result};
87#[cfg(feature = "event_ingestion")]
88pub use sdk_key::SdkKey;
89pub use sdk_metadata::SdkMetadata;