初始化 fanyi 翻译 CLI 项目

- 项目从 fyy 更名为 fanyi
- 添加 clap 命令行参数解析
- 实现语言检测功能
- 配置异步运行时和 HTTP 客户端依赖
- 创建 TUTORIAL.md 教学计划文档
This commit is contained in:
sinlatansen
2026-02-19 15:32:06 +08:00
commit 851839ecd2
5 changed files with 2178 additions and 0 deletions

46
src/main.rs Normal file
View File

@@ -0,0 +1,46 @@
use clap::Parser;
use serde::Deserialize;
#[derive(Parser)]
#[command(name = "fyy")]
struct Args {
input: String,
}
#[derive(Deserialize)]
struct ApiResponse {
choices: Vec<Choice>,
}
#[derive(Deserialize)]
struct Choice {
message: Message,
}
#[derive(Deserialize)]
struct Message {
content: String,
}
fn is_chinese(text: &str) -> bool {
let first = text.chars().next();
match first {
Some(c) => {
if c >= '\u{4e00}' && c <= '\u{9fff}' {
true
} else {
false
}
}
None => false,
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = Args::parse();
println!("input: {}", args.input);
println!("is_chinese: {}", is_chinese(&args.input));
Ok(())
}