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.
[dependencies]
qrcode = "0.14"
image = "0.25" # For PNG outputGenerate QR Codes with Rust
Code examples using the qrcode crate.
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!");
}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!");
}Generate QR Codes via API in Rust
Call the QRCode.fun API from Rust using reqwest for styled QR codes.
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.
Native Library vs API
Compare using the qrcode crate versus the QRCode.fun API.
| Feature | qrcode Crate | QRCode.fun API |
|---|---|---|
| Setup complexity | cargo add + image crate for PNG | Single HTTP request via reqwest |
| Customization | Colors via image crate | Full styling: colors, shapes, logos |
| Offline support | Yes | Requires internet |
| Maintenance | cargo update | Always up-to-date |
| Output formats | SVG, PNG (with image crate), terminal | PNG, 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.
Start generating QR codes with Rust
Use our free generator or integrate the API into your Rust applications.