I have spent the last 4 days trying to figure this one out and I'm really really stuck. Basically I have a large number of similar structs, all containing one particular field. let's call it data of type u32:
struct A {
data: u32,
}
struct B {
data: u32
}
...
struct N {
data: u32
}
What I need to do is write a function outside those structs, which takes a generic type (that is, either one of those structs) perform some manipulation on the field and return the value. Basically something along the lines of:
fn some_manipulation<T>(st: &T) -> u32 {
st.data * 10
}
Which, as it stands, is not possible because there is no data field on type T. Another thing is I cannot modify the structs. Is there a sensible way to achieve this?