在 Rust 中通过另一个箱子访问一个箱子

Accessing one crate through another in Rust

我想通过 Cucumber 导入 serde_jsongherkin_rust v0.10.1 将其列在“[build-dependencies]”下。如何在不将其添加到 toml 文件/使用 extern crate 调用的情况下访问它?

 └── cucumber v0.10.2
    ├── gherkin_rust v0.10.1
    │   ├── peg v0.6.3
    │   │   ├── peg-macros v0.6.3 (proc-macro)
    │   │   │   ├── peg-runtime v0.6.3
    │   │   │   ├── proc-macro2 v1.0.32 (*)
    │   │   │   └── quote v1.0.10 (*)
    │   │   └── peg-runtime v0.6.3
    │   ├── textwrap v0.12.1
    │   │   └── unicode-width v0.1.9
    │   ├── thiserror v1.0.30
    │   │   └── thiserror-impl v1.0.30 (proc-macro)
    │   │       ├── proc-macro2 v1.0.32 (*)
    │   │       ├── quote v1.0.10 (*)
    │   │       └── syn v1.0.81 (*)
    │   └── typed-builder v0.7.1 (proc-macro)
    │       ├── proc-macro2 v1.0.32 (*)
    │       ├── quote v1.0.10 (*)
    │       └── syn v1.0.81 (*)
    │   [build-dependencies]
    │   ├── heck v0.3.3
    │   │   └── unicode-segmentation v1.8.0
    │   ├── quote v1.0.10 (*)
    │   ├── serde v1.0.130
    │   │   └── serde_derive v1.0.130 (proc-macro)
    │   │       ├── proc-macro2 v1.0.32 (*)
    │   │       ├── quote v1.0.10 (*)
    │   │       └── syn v1.0.81 (*)
    │   ├── serde_json v1.0.68
    │   │   ├── itoa v0.4.8
    │   │   ├── ryu v1.0.5
    │   │   └── serde v1.0.130 (*)
    │   └── syn v1.0.81 (*)
   

不能通过另一个 crate 访问它,除非另一个 crate 重新导出它公开(例如 pub use::cool_crate)。

只需将您需要的任何内容添加到 Cargo.toml。请注意,依赖项不会被多次使用,因此应该没有任何区别,但通过命名空间使用。