pub struct Experiment {
pub id: String,
pub name: String,
pub description: String,
pub rollout_percentage: u8,
pub enabled: bool,
pub variant_weights: Option<HashMap<String, u8>>,
pub sticky: bool,
}Expand description
Experiment configuration for A/B testing.
§Example
use chie_shared::{Experiment, Variant};
let exp = Experiment::new("new_ui_redesign", "Test new UI design")
.with_rollout_percentage(10); // Start with 10% traffic
// Check if a user is in the experiment
let user_id = "user123";
let variant = exp.assign_variant(user_id);Fields§
§id: StringUnique experiment identifier
name: StringHuman-readable experiment name
description: StringExperiment description
rollout_percentage: u8Rollout percentage (0-100)
enabled: boolWhether the experiment is currently active
variant_weights: Option<HashMap<String, u8>>Optional variant weights (must sum to 100)
sticky: boolSticky assignment: same user always gets same variant
Implementations§
Source§impl Experiment
impl Experiment
Sourcepub fn with_description(self, description: impl Into<String>) -> Self
pub fn with_description(self, description: impl Into<String>) -> Self
Set the experiment description.
Sourcepub fn with_rollout_percentage(self, percentage: u8) -> Self
pub fn with_rollout_percentage(self, percentage: u8) -> Self
Set the rollout percentage (0-100).
Sourcepub fn with_variant_weights(self, weights: HashMap<String, u8>) -> Self
pub fn with_variant_weights(self, weights: HashMap<String, u8>) -> Self
Set custom variant weights.
Sourcepub fn non_sticky(self) -> Self
pub fn non_sticky(self) -> Self
Disable sticky assignment (allow variant to change per request).
Sourcepub fn assign_variant(&self, user_id: &str) -> Variant
pub fn assign_variant(&self, user_id: &str) -> Variant
Assign a variant to a user based on their ID.
Uses a hash-based deterministic assignment for consistency.
Sourcepub fn is_enrolled(&self, user_id: &str) -> bool
pub fn is_enrolled(&self, user_id: &str) -> bool
Check if a user is enrolled in the experiment.
Trait Implementations§
Source§impl Clone for Experiment
impl Clone for Experiment
Source§fn clone(&self) -> Experiment
fn clone(&self) -> Experiment
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Experiment
impl Debug for Experiment
Source§impl<'de> Deserialize<'de> for Experiment
impl<'de> Deserialize<'de> for Experiment
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Experiment
impl RefUnwindSafe for Experiment
impl Send for Experiment
impl Sync for Experiment
impl Unpin for Experiment
impl UnwindSafe for Experiment
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more