如何使用本地未发布的板条箱? [英] How to use a local unpublished crate?

查看:36
本文介绍了如何使用本地未发布的板条箱?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个库:

cargo new my_lib

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

cargo new my_program --bin

extern crate my_lib;fn 主 {println!("你好,世界!");}

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

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

<预><代码>.├── my_lib└── my_program

希望这是有道理的.

我以为我可以按照货物指南覆盖路径,但它指出

<块引用>

您不能使用此功能告诉 Cargo 如何查找本地未发布的 crate.

这是使用最新稳定版 Rust (1.3) 时的情况.

解决方案

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

[dependencies.my_lib]路径 = "../my_lib"

或等效的替代 TOML:

[依赖项]my_lib = { path = "../my_lib" }

查看货物文档以指定依赖项了解更多信息详细信息,例如如何使用 git 存储库而不是本地路径.

I've made a library:

cargo new my_lib

and I want to use that library in a different program:

cargo new my_program --bin

extern crate my_lib;

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

what do I need to do to get this to work?

They aren't in the same project folder.

.
├── my_lib
└── my_program

Hopefully this makes sense.

I thought I'd be able to override the path as per the Cargo guide, but it states

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

This is when using the latest stable version of Rust (1.3).

解决方案

Add a dependency section to your executable's Cargo.toml and specify the path:

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

or the equivalent alternate TOML:

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

Check out the Cargo docs for specifying dependencies for more detail, like how to use a git repository instead of a local path.

这篇关于如何使用本地未发布的板条箱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆