dump.rsannotateddump.rssource48 lines · 2.6 KB · raw

Writes each kind of card to a directory, to look at. cargo run -p card --example dump -- /tmp/cards

3use archive::{Answer, Detail};
4use card::{Card, Commit};
6fn main() {
7    let dir = std::env::args().nth(1).expect("a directory to write into");
8    let answer = |headline: &str, detail: Detail| Answer { headline: headline.to_owned(), detail };
9    let pairs = |pairs: &[(&str, f64)]| pairs.iter().map(|(label, p)| ((*label).to_owned(), *p)).collect::<Vec<_>>();
10    let noul = [answer("No?", Detail::Noul { p_yes: 0.36 })];
11    let odds = [answer("28%.", Detail::Chance { p: 0.28 })];
12    let pick = [answer(
13        "Pepperoni.",
14        Detail::Choice { confidence: 0.95, options: pairs(&[("Pepperoni", 0.9), ("Mushroom", 0.06), ("Pineapple", 0.03), ("Olive", 0.01)]) },
15    )];
16    let scale = [answer(
17        "1-5 times.",
18        Detail::Score {
19            score: 1.2,
20            confidence: 0.61,
21            levels: pairs(&[("0 times", 0.09), ("1-5 times", 0.62), ("6-10 times", 0.22), ("11-20 times", 0.05), ("more than 20 times", 0.02)]),
22        },
23    )];
24    let two = [answer("Yes.", Detail::Noul { p_yes: 0.92 }), pick[0].clone()];
25    let old = [answer("No?", Detail::Unknown)];
26    let long = "is python slower than rust, and which of the two is better for a beginner who has never programmed?";
27    let latest = Commit {
28        sha: "4d93353abcdef".to_owned(),
29        subject: "clone: the token is LMJTFY_GITHUB_TOKEN, from the op environment like the Jev key".to_owned(),
30        date: "2026-10-02".to_owned(),
31        count: Some(140),
32    };
33    let url = "https://lmjtfy.fun/lmjtfy.git";
34    let cards = [
35        ("code", Card::Code { name: "lmjtfy.git", url, recurse: true, about: "This site: Rust on Cloudflare Workers, a rules engine, and Jev.", branch: "main", latest: Some(&latest) }),
36        ("home", Card::Home),
37        ("noul", Card::Question { input: "Will CT leave the casino with more money?", said: &noul }),
38        ("odds", Card::Question { input: "What are the chances that all recent slot machines are vibe-coded?", said: &odds }),
39        ("pick", Card::Question { input: "what is the best pizza topping", said: &pick }),
40        ("scale", Card::Question { input: "How many times can you double your bet before going broke?", said: &scale }),
41        ("two", Card::Question { input: long, said: &two }),
42        ("old", Card::Question { input: "is AI a bit stupid?", said: &old }),
43        ("unasked", Card::Question { input: "will it rain tomorrow?", said: &[] }),
44    ];
45    for (name, card) in cards {
46        std::fs::write(format!("{dir}/{name}.png"), card::png(card)).expect("the directory is writable");
47    }
48}