Files
QRGen/examples/basic_qr.rs
T
Serendipity ce8063431e docs: 开源规范化 — doc comments + 社区文件 + 示例代码 + crates.io 就绪
- 为 core 公开 API 添加完整 doc comments(rustdoc 可用)
- 新增 .editorconfig / CONTRIBUTING / CODE_OF_CONDUCT / SECURITY
- 新增 Issue 模板(bug + feature)+ PR 模板
- 新增 3 个代码示例(examples/)
- 更新 Cargo.toml 元数据(description/repository/keywords/categories/MSRV)
- 更新 README + CHANGELOG
2026-06-19 18:56:28 +08:00

31 lines
826 B
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! QRGen 基础示例:生成 QR 码并导出为多种格式
//!
//! 运行: `cargo run --example basic_qr`
use qr_core::qr::{QrCode, QrConfig};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let text = "https://github.com/LHY0125/QRGen";
// 使用默认配置(M 级纠错,自动版本,4 模块边距)
let qr = QrCode::encode(text, QrConfig::default())?;
println!("版本: {}", qr.version.0);
println!("尺寸: {}×{} 模块", qr.size(), qr.size());
println!("掩码: {}", qr.mask);
// 终端 ASCII 预览
println!("\n--- ASCII 预览 ---");
println!("{}", qr.to_ascii(false));
// 导出 PNG
qr.to_png_bytes(8)?;
println!("\nPNG 生成成功");
// 导出 SVG
let svg = qr.to_svg();
println!("SVG 长度: {} 字节", svg.len());
Ok(())
}