Files
Serendipity cd75141037 refactor: P0-P5 全面架构重构
P1 thiserror 类型化错误:
新增 core/src/error.rs QrError 枚举, 全链 String -> QrError,
包括 EmptyInput/InvalidVersion/DataTooLong/DecodeFail 等 8 种变体

P2 text_builder Tauri 统一:
新增 build_qr_text Tauri command, 删除前端 qrText.ts,
所有 mode 组件改为 invoke 调用 Rust 端构建文本

P3 QrConfig 颜色字段移除:
从 QrConfig/QrCode 移除 fg_color/bg_color,
改为 to_svg/to_image_bytes 参数传递

P4 前端 4 项合并:
Context 拆分为 StateContext+DispatchContext (H10),
新建 useModeForm 通用 hook (M11),
VCardMode grid-cols-2 网格布局 (M13),
persistHistory/loadHistory 迁至 utils/storage.ts (L9)

P5 算法优化:
MaskedView 懒计算替代 8 次 Matrix 克隆 (H9),
encoding_rs 精确 Kanji Shift JIS 映射 (H12)

验证: cargo check+clippy 通过, 81+24+7 全部测试通过
2026-06-21 15:09:10 +08:00

31 lines
883 B
Rust
Raw Permalink 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
let _png = qr.to_png_bytes(8, None)?;
println!("\nPNG 生成成功 ({} 字节)", _png.len());
// 导出 SVG
let svg = qr.to_svg(None, None, None);
println!("SVG 长度: {} 字节", svg.len());
Ok(())
}