rust - 在toml中导入带有别名的rust包

标签 rust rust-crates toml

我正在尝试制作一个简单的程序来检查同一rust项目的两个不同分支上的执行时间。
我想让我的.toml看起来像这样

[dependencies]
cron_original = { git = "https://github.com/zslayton/cron" }
cron_fork = { git = "https://github.com/koenichiwa/cron", branch = "feature/reimplement-queries"}
我的程序如下所示:
fn main() {
    let expression = String::from("0-59 * 0-23 ?/2 1,2-4 ? *");
    let schedule_orig = cron_original::Schedule::from_str(expression);
    let schedule_fork = cron_fork::Schedule::from_str(expression);
    // Check difference in execution times on these structs
}
但我得到no matching package named 'cron_fork' found。无论如何,有没有导入带有特定别名的软件包?我正在考虑创建可以自动执行此类检查的内容。

最佳答案

您需要为这些依赖项指定package键,这样即使您指定了其他名称, cargo 也知道您确实想要这些软件包:

[dependencies]
cron_original = { git = "https://github.com/zslayton/cron", package="cron" }
cron_fork = { git = "https://github.com/koenichiwa/cron", branch = "feature/reimplement-queries", package="cron" }
有关详细信息,请参见Specifying Dependencies文档中的Cargo.toml中的重命名依赖项部分。

关于rust - 在toml中导入带有别名的rust包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66289830/

相关文章:

windows - 如何使 Libsodium 可用于 Windows 上的 Rust(初学者指南)?

我可以发布一个使用补丁的 crate 吗?

rust - 使用 serde 反序列化带有 Enum 键的 HashMap

数组内的 TOML 多级表语法——非法与否

python - 在 pyproject.toml 中连接 2 个数组

memory - 为什么Rust中的打印内存地址同时包含40位和48位地址?

rust - 作为函数指针类型 : what is the correct type definition? 的异步函数

rust - 当 crate 既是 Rust 库又是可执行文件时,应该提交 Cargo.lock 吗?

module - 是否有可能有一个模块,部分可以在 crate 外部访问,部分只能在 crate 内部访问?

rust - 如何检查路径是否存在?