gpt4 book ai didi

rust - 如何使用本地未发布的箱子?

转载 作者:行者123 更新时间:2023-11-29 08:31:34 25 4
gpt4 key购买 nike

我做了一个图书馆:

cargo new my_lib

我想在不同的程序中使用该库:

cargo new my_program --bin
extern crate my_lib;

fn main {
println!("Hello, World!");
}

我需要做什么才能让它发挥作用?

它们不在同一个项目文件夹中。

.
├── my_lib
└── my_program

希望这是有道理的。

我想我可以根据 Cargo guide 覆盖路径, 但它指出

You cannot use this feature to tell Cargo how to find local unpublished crates.

这是在使用最新的稳定版 Rust (1.3) 时。

最佳答案

将依赖部分添加到可执行文件的 Cargo.toml 并指定路径:

[dependencies.my_lib]
path = "../my_lib"

或等效的替代 TOML:

[dependencies]
my_lib = { path = "../my_lib" }

查看 Cargo docs for specifying dependencies有关更多详细信息,例如如何使用 git 存储库而不是本地路径。

关于rust - 如何使用本地未发布的箱子?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56466367/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com