Rust QR Code Library

Generate QR Codes with Rust

Rust's qrcode crate provides fast, memory-safe QR code generation. Ideal for high-performance applications, WebAssembly, and system-level tools.

Installation

Add the qrcode crate to your Cargo.toml.

Cargo.toml
[dependencies]
qrcode = "0.14"
image = "0.25"  # For PNG output

Generate QR Codes with Rust

Code examples using the qrcode crate.

QR Code as SVG
use qrcode::QrCode;
use qrcode::render::svg;

fn main() {
    let code = QrCode::new("https://qrcode.fun").unwrap();
    let svg = code.render::<svg::Color>()
        .min_dimensions(200, 200)
        .build();

    std::fs::write("qrcode.svg", &svg).unwrap();
    println!("SVG QR code saved!");
}
QR Code as PNG
use qrcode::QrCode;
use image::Luma;

fn main() {
    let code = QrCode::new("https://qrcode.fun").unwrap();
    let image = code.render::<Luma<u8>>()
        .dark_color(Luma([26u8]))
        .light_color(Luma([255u8]))
        .quiet_zone(true)
        .min_dimensions(300, 300)
        .build();

    image.save("qrcode.png").unwrap();
    println!("PNG QR code saved!");
}
QRCode.fun API

Generate QR Codes via API in Rust

Call the QRCode.fun API from Rust using reqwest for styled QR codes.

Rust API Integration
use reqwest;
use serde_json::json;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();
    let response = client
        .post("https://qrcode.fun/api/generate-qr-styled")
        .json(&json!({
            "data": "https://qrcode.fun",
            "width": 300,
            "height": 300,
            "type": "png",
            "margin": 10,
            "dotsOptions": { "color": "#1A2B3C", "type": "rounded" },
            "cornersSquareOptions": { "color": "#8564C3", "type": "extra-rounded" },
            "backgroundOptions": { "color": "#FFFFFF" }
        }))
        .send()
        .await?;

    let result: serde_json::Value = response.json().await?;
    println!("{}", &result["data"].as_str().unwrap()[..50]);
    Ok(())
}

Live QR Code Preview

Try generating a QR code with Rust right now.

QR preview

Native Library vs API

Compare using the qrcode crate versus the QRCode.fun API.

Featureqrcode CrateQRCode.fun API
Setup complexitycargo add + image crate for PNGSingle HTTP request via reqwest
CustomizationColors via image crateFull styling: colors, shapes, logos
Offline supportYesRequires internet
Maintenancecargo updateAlways up-to-date
Output formatsSVG, PNG (with image crate), terminalPNG, SVG

Rust QR Code Use Cases

Common scenarios for QR codes in Rust applications.

WebAssembly

Compile QR generation to WASM for blazing-fast browser-side QR code creation without JavaScript libraries.

CLI Tools

Build command-line utilities that generate QR codes for terminal display, file output, or clipboard integration.

High-Performance Servers

Generate QR codes in Actix or Axum web servers with minimal memory allocation and maximum throughput.

Embedded Systems

Run QR code generation on resource-constrained devices where Rust's zero-cost abstractions shine.

Frequently Asked Questions

Common questions about generating QR codes with Rust.

The qrcode crate is the most popular choice. It generates QR codes as SVG strings or as a matrix that you can render with the image crate.

Start generating QR codes with Rust

Use our free generator or integrate the API into your Rust applications.