Re-export struct with generics applied

Viewed 69

When re-exporting structs from crates, can you also specify some generics?

as in;

// file: transform.rs
pub use euclid::Transform2d as Transform<f32, f32, f32>;

// file: something-else.rs

use transform::Transform;

Transform::new(...); // notice no generics, as its been pre-applied

I know the above isn't valid rust, but that is the idea.

Why? It's for when I want to build an internal api, but do not want to specify this in any other way.

1 Answers

You can create a type alias and export it

pub mod module_1 {
    pub struct TypeWithGeneric<T> {
        field: T
    }
    
    pub type PublicType = TypeWithGeneric<u64>;
}

mod module_2 {
    use crate::module_1::PublicType;
    
    fn usage_of_type(_: PublicType) {
    }
}
Related