【rust-i18n】Cargo.toml 配置文件解析

toml 复制代码
[package]
authors = ["Jason Lee <huacnlee@gmail.com>"]  # 作者信息
build = "build.rs"                              # 构建脚本
categories = ["localization", "internationalization"]  # 包分类
description = "Rust I18n is use Rust codegen for load YAML file storage translations on compile time, and give you a t! macro for simply get translation texts."  # 详细描述
edition = "2021"                                 # Rust 版本(2021 edition)
exclude = ["crates", "tests"]                    # 发布时排除的目录
keywords = [
    "gettext",
    "i18n",
    "internationalization",
    "localization",
    "translation",
]  # 关键词
license = "MIT"                                   # 开源协议
name = "rust-i18n"                                # 包名
readme = "README.md"                              # README 文件
repository = "https://github.com/longbridge/rust-i18n"  # 仓库地址
version = "4.0.0-preview1"                        # 版本号(预览版)

1. 工作空间依赖 [workspace.dependencies]

这是工作空间级别的依赖定义,所有成员 crate 可以共享这些依赖:

toml 复制代码
[workspace.dependencies]
anyhow = "1"                                      # 错误处理
arc-swap = "1.6.0"                                # 原子引用计数
base62 = "2.0.2"                                  # Base62 编码
clap = { version = "4.1.14", features = ["derive"] }  # 命令行参数解析
criterion = "0.5"                                 # 基准测试
foo = { path = "examples/foo" }                   # 本地示例依赖
glob = "0.3"                                      # 文件路径匹配
globwalk = "0.8.1"                                # 文件遍历
ignore = "0.4"                                    # gitignore 规则匹配
indoc = "1"                                        # 多行字符串缩进
itertools = "0.11.0"                              # 迭代器工具
lazy_static = "1"                                 # 懒静态变量
normpath = "1.1.1"                                # 规范化路径
proc-macro2 = { version = "1", features = ["span-locations"] }  # 过程宏支持
quote = "1.0.2"                                    # 过程宏代码生成
regex = "1"                                        # 正则表达式
rust-i18n = { path = "." }                         # 主 crate
rust-i18n-extract = { path = "./crates/extract", version = "4.0.0-preview1" }  # 提取工具
rust-i18n-macro = { path = "./crates/macro", version = "4.0.0-preview1" }      # 过程宏
rust-i18n-support = { path = "./crates/support", version = "4.0.0-preview1" }  # 支持库
serde = { version = "1", features = ["derive"] }   # 序列化
serde_json = "1"                                   # JSON 支持
serde_yaml = "0.9.33"                              # YAML 支持
siphasher = "1.0"                                  # 哈希算法
smallvec = "1.12.0"                                # 小向量优化
syn = { version = "2.0.18", features = ["full", "extra-traits"] }  # Rust 语法解析
toml = "0.8.8"                                     # TOML 支持
triomphe = { version = "0.1.11", features = ["arc-swap"] }  # 引用计数智能指针

2. 主 crate 依赖 [dependencies]

toml 复制代码
[dependencies]
rust-i18n-support.workspace = true  # 使用工作空间定义的依赖
rust-i18n-macro.workspace = true    # 使用工作空间定义的依赖
smallvec.workspace = true            # 使用工作空间定义的依赖

3. 开发依赖 [dev-dependencies]

toml 复制代码
[dev-dependencies]
foo.workspace = true     # 示例项目
criterion.workspace = true  # 基准测试框架
lazy_static.workspace = true  # 懒静态变量
serde_yaml.workspace = true   # YAML 序列化

4. 构建依赖 [build-dependencies]

toml 复制代码
[build-dependencies]
globwalk.workspace = true  # 文件遍历
regex.workspace = true      # 正则表达式

5. 特性配置 [features]

toml 复制代码
[features]
log-miss-tr = ["rust-i18n-macro/log-miss-tr"]  # 启用缺失翻译日志功能

6. 示例配置 [[example]]

toml 复制代码
[[example]]
name = "app"
test = true  # 这个示例也可以作为测试运行

7. 工作空间成员 [workspace]

toml 复制代码
[workspace]
members = [
    "crates/cli",         # CLI 工具
    "crates/extract",      # 提取工具
    "crates/support",      # 支持库
    "crates/macro",        # 过程宏
    "examples/app-egui",   # egui UI 示例
    "examples/app-load-path",  # 加载路径示例
    "examples/app-metadata",   # 元数据示例
    "examples/app-minify-key", # 键最小化示例
    "examples/foo",        # 基础示例
]

8. 基准测试 [[bench]]

toml 复制代码
[[bench]]
harness = false  # 不使用默认测试框架
name = "bench"   # 基准测试名称

[[bench]]
harness = false
name = "minify_key"  # 键最小化性能测试

项目结构总结

这是一个国际化(i18n)库 ,采用工作空间组织方式:

  • 主 crate :提供 t! 宏用于翻译
  • 子 crates:包含宏实现、支持库、提取工具和 CLI
  • 功能:支持编译时加载 YAML 翻译文件
  • 版本:4.0.0 预览版,采用 Rust 2021 edition
  • 测试:包含示例程序、基准测试和单元测试
  • 特性:可选的缺失翻译日志功能
相关推荐
水月wwww18 小时前
Rust的安装与卸载 | windows
开发语言·windows·rust
Mem0rin19 小时前
[自用]Rust速通day5:包、crate和use
rust
Ivanqhz1 天前
活跃范围重写(Live Range Rewriting)
开发语言·c++·后端·算法·rust
Roc.Chang1 天前
Rust 入门 - RustRover 新建项目时四种项目模板对比
开发语言·后端·rust
勇敢牛牛_2 天前
【conreg-client】在Rust中使用向Feign一样的远程调用
网络·rust·feign
小杍随笔2 天前
【Rust模块化进阶:深入解析mod.rs的用法与现代实践(1.94版本)】
开发语言·后端·rust
@atweiwei2 天前
Tokio 深度解析:Rust 异步运行时与 Go 协程对比指南
服务器·网络·后端·golang·rust·内存·所有权
福大大架构师每日一题2 天前
2026年3月TIOBE编程语言排行榜,Go语言排名第16,Rust语言排名14。为什么 TIOBE 指数仍然依赖搜索引擎?
开发语言·搜索引擎·rust·tiobe
小杍随笔2 天前
【Rust可见性控制:pub、pub(crate)、pub(super)实战】
开发语言·后端·rust
Source.Liu2 天前
【Iced】core库下angle.rs文件分析
rust·iced