Registry / Framework

framework · v0.1.2
Gift Balance
Redeem a prepaid balance multiple times, decline overdrafts, and close an exhausted card.
Use Gift Balance
use vendor::gift_balance::gift_balance;
Run the example
nest demo gift_balance@0.1.2
blyxc native-run gift_balance-demo/main.blyx
Example source and expected output
use std::cli;
use std::text;
use vendor::gift_balance::gift_balance;
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 = gift_balance_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 = gift_balance_step(live, args_at(arguments, i), text_number(input));
let command = gift_balance_command(live);
println!(command);
if command == "reject" { process_exit(1); }
i += 2;
}
return;
}
let mut state = gift_balance_start();
state = gift_balance_step(state, "issue", 30.0);
println!(gift_balance_command(state));
state = gift_balance_step(state, "redeem", 31.0);
println!(gift_balance_command(state));
state = gift_balance_step(state, "redeem", 11.0);
println!(gift_balance_command(state));
state = gift_balance_step(state, "freeze", 0.0);
println!(gift_balance_command(state));
state = gift_balance_step(state, "resume", 0.0);
println!(gift_balance_command(state));
state = gift_balance_step(state, "redeem", 19.0);
println!(gift_balance_command(state));
}
Expected output
load_credit
reject
debit
suspend
enable
drain
Published versions
| Version | Package | Source commit | SHA-256 |
|---|---|---|---|
| 0.1.2 | Download ZIP · Browse files | e12c6aa33a | de386895610cc7ab63d2c74b7eabdca196d7a013883a3db9e7a3a11c7bc74f54 |
| 0.1.1 | Download ZIP · Browse files | e30941a1e4 | 55406526d6e0b31c9ad802a507003f93c1caecdf1ddcd8dc2010f533623b0e3e |
| 0.1.0 | Download ZIP · Browse files | 6349f23784 | 337a7f8a027f44b0b6fad117d8019c2109eaab2ecf3a96c2868c52a207240ddf |