重构到工作空间结构会导致外部包装箱导入不起作用

时间:2018-04-07 23:08:48

标签: rust rust-cargo

我需要项目的不同部分使用相同extern crate的不同版本,因此我将使用this作为指南,通过工作区系统将我的Rust项目重构为多个包。这样做会导致我的所有pub extern crate导入无效。

此帖与我最近创建的帖子非常相似,然后被删除 - 此版本包含一个最小,完整且可验证的示例。

这是我的项目结构

workspace_test/
  root/
    src/
      main.rs
    Cargo.toml
  Cargo.toml

workspace_test / Cargo.toml:

[package]
name = "workspace_test"
version = "0.1.0"
authors = ["Phoenix <kahlo.phoenix@gmail.com>"]

[workspace]
members = [
    "root"
]

[[bin]]
name = "root"
path = "root/src/main.rs"

workspace_test /根/ Cargo.toml:

[package]
name = "root"
version = "0.1.0"
authors = ["Phoenix <kahlo.phoenix@gmail.com>"]

[dependencies]
time = "0.1"

workspace_test /根/ SRC / main.rs:

pub extern crate time;

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

This is also on github,因此可以轻松克隆并cargo run

这是错误:

error[E0463]: can't find crate for `time`
 --> root/src/main.rs:1:1
  |
1 | pub extern crate time;
  | ^^^^^^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to previous error

error: Could not compile `workspace_test`.

1 个答案:

答案 0 :(得分:1)

{ Category = "Access Denied"; Error = YES; Objects = { Channels = ( "myglobalchannel", "myglobalchannel-pnpres" ); }; Operation = Subscribe; Region = { Current = "-1"; Previous = "<empty>"; }; Request = { Authorization = maftaf5dzfVcATrHQjMahUQlEb92UNZu; Method = GET; Origin = "ps.pndsn.com"; "POST Body size" = 0; Secure = YES; URL = "https://ps.pndsn.com/v2/subscribe/sub-c-809672b6-2c40-11e8-8305-f27a6a4e1feb/myglobalchannel,myglobalchannel-pnpres/0?deviceid=4810A924-0CD4-4C1C-A239-3E2028895F0E&uuid=pn-450E2851-77DA-47F2-A95E-F7D053F36EFE&requestid=4BD7D461-2ABE-411D-96E7-6E4F80951C5A&pnsdk=PubNub-ObjC-iOS%2F4.7.7&tt=0&instanceid=0F979806-2011-4898-A708-E5672E725FAF&auth=maftaf5dzfVcATrHQjMahUQlEb92UNZu"; UUID = "pn-450E2851-77DA-47F2-A95E-F7D053F36EFE"; }; Response = { "Processed data" = { channelGroups = ( ); channels = ( "myglobalchannel-pnpres" ); information = Forbidden; }; "Status code" = 403; }; Time = { Current = 0; Previous = 0; }; 中,您创建了一个包含二进制文件public class smartoutage { public static void main(final String[] args){ System.out.println(getLastBitFromUrl( "http://goxsd5174:3807/PD/outage/areaEtr/v1/device/40122480?param=true")); } public static String getLastBitFromUrl(final String url){ return url.replaceFirst(".*/([^/?]+).*", "$1"); } } 的包。如果执行System.out.println("Enter First Name"); String input = in.next(); queueArray[last].setfName(input.toUpperCase()); while(!input.matches("[a-zA-Z,]+")){ System.out.println("Invalid Input"); System.out.printLn("Enter First Name"); queueArray[last].setfName(in.next().toUpperCase()); } ,它将运行workspace_test/Cargo.toml,但由于您未在此清单文件中说明依赖项,因此会发生错误。依赖关系仅在root中指定,此时未使用。

我假设你想使用RFC提出的工作空间。您可以使用虚拟清单创建工作区,该清单既不能指定cargo run也不能指定main.rs,因此只需删除它们即可。 workspace_test/root/Cargo.toml现在看起来像这样:

[package]

如果您只有一个可执行文件,现在可以传递包:[[bin]]

workspace_test/Cargo.toml

或手动指定清单路径:

[workspace]
members = [
    "root"
]

如果-p/--package包含多个目标,您可以像往常一样附加cargo run -p root cargo run --manifest-path root/Cargo.toml 个标记。例如。这将执行root/Cargo.toml中指定的--lib - 二进制文件:

--bin