Expand description
Deterministic A/B test bucketing.
get_bucket hashes experiment_name:unique_id with SHA-256 and maps it to
one of 10,000 buckets, so a user always gets the same variant within an
experiment and independent variants across experiments. Raising exposure
only adds users; it never moves anyone between variants.
Assignments are byte-for-byte identical to the abtestify npm package and the Go, Python, Java/Kotlin and Swift ports. Shared test vectors in the repository enforce it. The crate has no dependencies.
use abtestify::{get_bucket, Params};
let assignment = get_bucket(&Params::new("checkout-cta", "user-5")).unwrap();
assert_eq!(assignment.resolved_variant, "treatment");
let ramp = Params::new("checkout-cta", "user-5")
.treatment_split(20.0)
.exposure(10.0);
println!("{}", get_bucket(&ramp)?.resolved_variant);Structs§
- Assignment
- The variant a user is assigned to.
- Params
- Input for
get_bucket.
Enums§
- Error
- Invalid input to
get_bucket. Fields are checked in declaration order.
Constants§
- BUCKETS
- Number of buckets users are spread across.
Functions§
- get_
bucket - Assigns
params.unique_idto a variant ofparams.experiment_name.