Registry / Framework

framework · v0.1.2
Coupon Pool
Manage a finite campaign redemption pool with replenishment and explicit suspension.
Use Coupon Pool
use vendor::coupon_pool::coupon_pool;
Run the example
nest demo coupon_pool@0.1.2
blyxc native-run coupon_pool-demo/main.blyx
Example source and expected output
use std::cli;
use std::text;
use vendor::coupon_pool::coupon_pool;
fn main() {
let arguments = cli_args();
if args_len(arguments) > 0 {
if args_len(arguments) % 2 != 0 {
stderr_line("Expected event and value pairs");
process_exit(2);
}
let mut live = coupon_pool_start();
let mut i = 0;
while i < args_len(arguments) {
let input = args_at(arguments, i + 1);
if !text_is_number(input) {
stderr_line("Expected a whole numeric event value");
process_exit(2);
}
live = coupon_pool_step(live, args_at(arguments, i), text_number(input));
let command = coupon_pool_command(live);
println!(command);
if command == "reject" { process_exit(1); }
i += 2;
}
return;
}
let mut state = coupon_pool_start();
state = coupon_pool_step(state, "launch", 3.0);
println!(coupon_pool_command(state));
state = coupon_pool_step(state, "pause", 0.0);
println!(coupon_pool_command(state));
state = coupon_pool_step(state, "redeem", 1.0);
println!(coupon_pool_command(state));
state = coupon_pool_step(state, "resume", 0.0);
println!(coupon_pool_command(state));
state = coupon_pool_step(state, "redeem", 3.0);
println!(coupon_pool_command(state));
state = coupon_pool_step(state, "refill", 2.0);
println!(coupon_pool_command(state));
}
Expected output
publish_offer
pause_offer
reject
publish_offer
hide_offer
publish_offer
Published versions
| Version | Package | Source commit | SHA-256 |
|---|---|---|---|
| 0.1.2 | Download ZIP · Browse files | fc4139e38c | dbea6cf0d630dd07d5ba4c289f7010fd422f701441687baaaa9a6f27adb05906 |
| 0.1.1 | Download ZIP · Browse files | 65003db444 | 7b7e0473f081ea85571b0cf817e8dacae6a4e4506a374af93615ee9355f6ee53 |
| 0.1.0 | Download ZIP · Browse files | 6349f23784 | 19dec15f31905f1e9ffac8202eda5a937ea1525b6f9f291d806b92489ed774f6 |