Rust QR코드 라이브러리

Rust로 QR코드 생성

Rust의 qrcode crate는 빠르고 메모리 안전한 QR코드 생성을 제공합니다. 고성능 애플리케이션, WebAssembly, 시스템 레벨 도구에 이상적입니다.

설치

qrcode crate를 Cargo.toml에 추가하세요.

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

Rust로 QR코드 생성

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

Rust에서 API로 QR코드 생성

reqwest를 사용하여 Rust에서 QRCode.fun API를 호출하여 스타일 QR코드를 생성하세요.

Rust API 통합
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(())
}

QR코드 라이브 미리보기

지금 바로 Rust로 QR코드를 생성해 보세요.

QR 미리보기

네이티브 라이브러리 vs API

qrcode crate와 QRCode.fun API 비교.

기능qrcode CrateQRCode.fun API
설정 복잡도cargo add + PNG용 image cratereqwest를 통한 단일 HTTP 요청
커스터마이징image crate를 통한 색상전체 스타일링: 색상, 모양, 로고
오프라인 지원인터넷 필요
유지보수cargo update항상 최신 상태
출력 형식SVG, PNG (image crate 사용), 터미널PNG, SVG

Rust QR코드 사용 사례

Rust 애플리케이션에서 QR코드의 일반적인 시나리오.

WebAssembly

QR코드 생성을 WASM으로 컴파일하여 JavaScript 라이브러리 없이 브라우저 측에서 초고속 QR코드 생성을 구현합니다.

CLI 도구

터미널 표시, 파일 출력, 클립보드 통합을 위한 QR코드를 생성하는 커맨드라인 유틸리티를 구축합니다.

고성능 서버

Actix 또는 Axum 웹 서버에서 최소 메모리 할당과 최대 처리량으로 QR코드를 생성합니다.

임베디드 시스템

리소스가 제한된 장치에서 QR코드 생성을 실행하여 Rust의 제로 비용 추상화의 장점을 활용합니다.

자주 묻는 질문

Rust로 QR코드 생성에 관한 일반적인 질문.

qrcode crate가 가장 인기 있는 선택입니다. QR코드를 SVG 문자열이나 매트릭스로 생성하며, image crate로 렌더링할 수 있습니다.

Rust로 QR코드 생성 시작하기

무료 생성기를 사용하거나 API를 Rust 애플리케이션에 통합하세요.