Hi,
I have a free standing function inside a mode that I want to accept some generics:
fn my_generics_function<T>( param1: &T, param2: &T) {
and in the same module it is called:
my_generics_function::<CStruct1>(¶m1, ¶m2);
The problem :
the compiler compains that param of type T
doesn't have field0
;
error[E0609]: no field `field0` on type `&T`
If I make the function non generic:
fn my_generics_function( param1: &CStruct1, param2: &CStruct1) {
it works.
I also tried
my_generics_function(¶m1, ¶m2);
with the same result.
param1 and param2 are of type:
Simplified code (changed names and all for a better focus):
enum Enum0{
VALUE0,
VALUE1,
}
pub(crate) struct CStruct1 {
pub(crate) field0: Enum0,
...
}
fn my_generics_function<T>( param1: &T, param2: &T) {
...
param1.field0 // <- error here
...
}
fn other_function(){
...
let param1 : CStruct1;
...
my_generics_function(¶m1, ¶m2); // or my_generics_function::<CStruct1>(¶m1, ¶m2);
...
}
I desperately tried #![feature(min_specialization)]
in my lib.rs with the same result.
My current workaround is to manually copy/paste code with the specific type.
So not a show stopper; But if there is a better way, usable right now in the nightly compiler, I take it.
Thanks!