我正在尝试重新导出第三方板条箱,以便我的库的消费者不必手动添加通过 proc 宏生成的某些代码所需的所有依赖项。
但是,我似乎无法获得编译器要解析的路径,即使我获得了导航到该路径的代码完成。
如何从我自己的包中正确地重新导出第三方包,以便使用我的 proc 宏的包的消费者不必手动添加第三方包来支持生成的代码?
下面是一个简化的示例,它应该与我的问题等同,即使我的真实项目在由我自己的 proc 宏生成的代码中解析此路径时存在问题。
文件结构:
│ Cargo.lock
│ Cargo.toml
│ rust-toolchain.toml
│
├───consumer
│ │ .gitignore
│ │ Cargo.toml
│ │
│ └───src
│ main.rs
│
└───exporter
│ .gitignore
│ Cargo.toml
│
└───src
lib.rs
在我的“消费者”板条箱中,我尝试使用板条箱Debug
提供的派生宏derive_more
。
消费者中的 Main.rs:
#[derive(exporter::reexports::derive_more::Debug)]
pub struct Foo {
x: u64
}
fn main() {
println!("Hello, world!");
}
消费者中的 Cargo.toml:
[package]
name = "consumer"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
exporter = { path = "../exporter" }
导出器中的 lib.rs:
pub mod reexports {
pub use derive_more;
}
出口商中的 Cargo.toml:
[package]
name = "exporter"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
derive_more = { version = "2", features = ["full"] }