【typenum】 0 配置文件(Cargo.toml)
源码解析
这是一个 Rust 项目的 Cargo.toml 配置文件,用于 typenum 库(一个在编译时处理类型级数字的 Rust 库)。
[package]
name = "typenum"
version = "1.18.0" # remember to update html_root_url
authors = ["Paho Lurie-Gregg <paho@paholg.com>", "Andre Bogus <bogusandre@gmail.com>"]
documentation = "https://docs.rs/typenum"
repository = "https://github.com/paholg/typenum"
readme = "README.md"
license = "MIT OR Apache-2.0"
description = """Typenum is a Rust library for type-level numbers evaluated atcompile time. It currently supports bits, unsigned integers, and signedintegers. It also provides a type-level array of type-level numbers, but itsimplementation is incomplete."""
categories = ["no-std"]
edition = "2018"
rust-version = "1.37.0"
exclude = ["/.github/","/clippy.toml","/flake.lock","/flake.nix","/justfile","/.envrc",
][dependencies]
scale-info = { version = "1.0", default-features = false, optional = true }[lib]
name = "typenum"[features]
no_std = [] # Deprecated
i128 = []
strict = []
force_unix_path_separator = [] # Deprecated
const-generics = []
scale_info = ["scale-info/derive"][package.metadata.docs.rs]
features = ["i128", "const-generics"]
rustdoc-args = ["--cfg", "docsrs"][package.metadata.playground]
features = ["i128", "const-generics"][workspace]
members = ["generate"]
[package] 部分
-
基础信息:
-
name = “typenum”:包名。
-
version = “1.18.0”:当前版本。
-
-
authors:维护者列表。
-
edition = “2018”:使用的 Rust 版本(2018 版)。
-
rust-version = “1.37.0”:最低支持的 Rust 编译器版本。
-
项目描述:
-
description:库的功能说明(编译时类型级数字计算,支持位、无符号/有符号整数等)。
-
license = “MIT OR Apache-2.0”:双许可证(用户可选 MIT 或 Apache-2.0)。
-
categories = [“no-std”]:属于 no-std 分类(不依赖标准库)。
-
-
文档和代码库:
-
documentation:指向 docs.rs 上的文档。
-
repository:GitHub 仓库地址。
-
readme = “README.md”:项目根目录的 README 文件。
-
-
排除文件:
- exclude:列出不包含在发布包中的文件/目录(如 GitHub 配置、构建工具文件等)。
[dependencies] 部分
- 唯一依赖项:
scale-info = { version = "1.0", default-features = false, optional = true }
-
条件依赖(optional = true):仅当启用 scale_info 特性时才会引入。
-
禁用默认特性(default-features = false),通常用于 no-std 环境。
[lib] 部分
- name = “typenum”:库的入口文件名(默认为 src/lib.rs)。
[features] 部分
定义可选的编译特性:
-
常规特性:
-
i128:支持 128 位整数。
-
const-generics:支持 Rust 的常量泛型。
-
-
废弃特性:
- no_std 和 force_unix_path_separator(已废弃,但保留兼容性)。
-
依赖关联特性:
- scale_info:启用 scale-info/derive 特性(依赖项的派生宏)。
[package.metadata] 部分
-
文档生成配置(docs.rs):
-
默认启用 i128 和 const-generics 特性。
-
传递 --cfg docsrs 参数给 rustdoc(用于条件编译文档)。
-
-
Playground 配置:
- 在 Rust Playground 中启用 i128 和 const-generics 特性。
[workspace] 部分
- members = [“generate”]:声明工作区成员(包含子项目 generate,可能用于代码生成)。
关键点总结
-
无标准库支持:通过 no-std 分类和条件依赖实现。
-
版本兼容性:支持 Rust 1.37.0 及以上。
-
特性控制:允许用户按需启用功能(如 128 位整数或常量泛型)。
-
文档优化:为 docs.rs 和 Playground 预设特性,确保文档完整性。
此配置体现了库的轻量级设计和对灵活性的重视,适合嵌入式或其他 no-std 场景。