Rust 模块
Rye 建议使用 maturin 开发 Rust Python 扩展模块。此过程在很大程度上是自动化的,可以使用 rye init
创建新项目。
新项目
rye init my-project --build-system maturin
cd my-project
将创建以下结构
.
├── .git
├── .gitignore
├── .python-version
├── README.md
├── pyproject.toml
├── Cargo.toml
├── python
└── my_project
└── __init__.py
└── src
└── lib.rs
迭代
当您使用 maturin 作为构建系统时,rye sync
将自动将 Rust 扩展模块构建到您的 venv 中。同样,rye build
将使用 maturin 触发轮式构建。为了更快的迭代,建议直接使用 maturin
。
如果您想使用其他 maturin 命令,例如 maturin develop
,您可以将其安装为全局工具
rye install maturin
Rye 建议使用混合的 Python/Rust 模块。在这种情况下,您可以通过运行 maturin develop --skip-install
节省一些宝贵的迭代时间。
maturin develop --skip-install