I am trying to write a generic function. I have the following code:
struct Car {
id: u8,
wheels: u8,
seatbelt: bool,
}
struct Motorcycle {
id: u8,
wheels: u8,
helmet: bool,
trait Vehicle {}
impl Vehicle for Car {}
impl Vehicle for Motorcycle {}
fn vehicle_info<T>(vehicle: T)
where
T: Vehicle,
{
println!("{} {}", vehicle.id, vehicle.wheels)
}
The compiler gives me error: no field id on type T.
Now the question is how do I promise to the compiler in the trait that all structs passed into the function have these certain fields?