Generics in crate boundaries
⚓ Rust 📅 2025-09-17 👤 surdeus 👁️ 12Let's say that we have a crate graph like this:
A exposes
pub fn entry_to_system<A: Trait>(ty: A) {} // This creates lots of generic stuff.
as MIR.
- If B and C use
entry_to_systemwith the same type, will the compiler need to build the same thing twice? - What if they use
dyn?
In these kinds of cases, would it be better to expose something like
fn entry_to_system<A: Trait>(ty: A) {}
pub struct MyType;
impl Trait for MyType {}
pub fn concrete_entry_to_system(ty: MyType) {
entry_to_system(ty)
}
// or
pub fn dyn_entry_to_system(ty: Box<dyn A>) {
entry_to_system(ty)
}
To avoid these issues?
4 posts - 2 participants
🏷️ Rust_feed
