Skip to main content

encode_qr

Function encode_qr 

Source
pub fn encode_qr(data: &str) -> Option<QrData>
Expand description

Encode an arbitrary string (URL, EPC-QR payload, plain text) into a QR module matrix suitable for Typst rendering. Medium error-correction level (Q) — robust while keeping module count low for clean look.

Examples found in repository?
examples/qr_matrix.rs (line 13)
6fn main() {
7    let args: Vec<String> = std::env::args().collect();
8    let data = args
9        .get(1)
10        .cloned()
11        .unwrap_or_else(|| "https://buy.stripe.com/test_ACME-STUDIO-S$28014".to_string());
12
13    let qr = encode_qr(&data).expect("encoding failed");
14    println!("#let qr-data = (");
15    println!("  size: {},", qr.size);
16    println!("  label: \"{}\",", qr.label);
17    println!("  modules: (");
18    for row in &qr.modules {
19        let cells: Vec<&str> = row
20            .iter()
21            .map(|b| if *b { "true" } else { "false" })
22            .collect();
23        println!("    ({}),", cells.join(", "));
24    }
25    println!("  ),");
26    println!(")");
27}