Generics in crate boundaries

⚓ Rust    📅 2025-09-17    👤 surdeus    👁️ 2      

surdeus

Let's say that we have a crate graph like this:

image

A exposes

pub fn entry_to_system<A: Trait>(ty: A) {} // This creates lots of generic stuff.

as MIR.

  1. If B and C use entry_to_system with the same type, will the compiler need to build the same thing twice?
  2. 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

Read full topic

🏷️ Rust_feed