【typenum】 0 配置文件(Cargo.toml)

源码解析

这是一个 Rust 项目的 Cargo.toml 配置文件,用于 typenum 库(一个在编译时处理类型级数字的 Rust 库)。

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 at
    compile time. It currently supports bits, unsigned integers, and signed
    integers. It also provides a type-level array of type-level numbers, but its
    implementation 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 部分

  • 唯一依赖项:
toml 复制代码
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,可能用于代码生成)。

关键点总结

  1. 无标准库支持:通过 no-std 分类和条件依赖实现。

  2. 版本兼容性:支持 Rust 1.37.0 及以上。

  3. 特性控制:允许用户按需启用功能(如 128 位整数或常量泛型)。

  4. 文档优化:为 docs.rs 和 Playground 预设特性,确保文档完整性。

此配置体现了库的轻量级设计和对灵活性的重视,适合嵌入式或其他 no-std 场景。

相关推荐
leikooo4 小时前
用餐厅和盘子理解栈和堆
java·数据结构·链表·rust
@大迁世界10 小时前
JEV RAG:更高效的 RAG 系统解决方案?
开发语言·rust
进击的雷神16 小时前
OpenClaw 太重、启动太慢?我试了试这个 Rust 重写的轻量版 AI 助手网关
开发语言·人工智能·rust·zeroclaw
选择即世界16 小时前
高性能的 SGLang Rust 运行时
rust
Ramble_Naylor1 天前
async/await:让一个线程同时等很多件事
开发语言·rust
Source.Liu2 天前
【A11】近期实现架构:面向 EPC 工作流企业 QQ 化的第一阶段
windows·架构·rust
geovindu2 天前
rust: Composite Pattern
开发语言·后端·设计模式·rust·组合模式
喵了几个咪3 天前
RushWind Admin — 契约驱动:203 条路由零手写的工程化拆解
微服务·rust·开源·admin
Ramble_Naylor3 天前
闭包与迭代器:函数式写法
rust