How to import a struct from a crate without importing unused dependencies?
⚓ Rust 📅 2025-08-14 👤 surdeus 👁️ 12Consider this setup:
// crate A
struct Example { field1: u8, field2: u8 }
impl Example {
fn use_lib() { ... }
}
// crate B
use crateA::Example;
Crate B uses a struct from crate A that has an associated function that uses a few crate A dependencies. These crate A dependencies that needed in crate B (only the struct is needed). Is there a way import the struct from crate A in crate B without importing all the dependencies of crate A?
Solutions I'm considering:
- Move
structinto crate C, create a wrapper in crate A and implement the functions on the wrapper - Create a macro that copies the
struct(without the associated functions) from crate A into crate B. A bit harder if thestructdepends on other structs defined in crate A.
Curious to hear other Ideas or thoughts
4 posts - 3 participants
🏷️ Rust_feed