Structs can contain generic fields as long as the generic parameters implement the appropriate EtherCrabWire* traits (e.g., EtherCrabWireRead).
Responsibility: The developer must ensure that the size of the generic type T matches the size specified by the #[wire(bits|bytes = N)] attribute on the containing struct.
Example
#[derive(ethercrab_wire::EtherCrabWireRead)]
#[wire(bytes = 2)]
struct Value {
#[wire(bytes = 2)]
raw: u16
};
#[derive(ethercrab_wire::EtherCrabWireRead)]
#[wire(bytes = 4)]
pub struct AnalogInput<T: ethercrab_wire::EtherCrabWireRead> {
// ... bit fields ...
#[wire(bits = 16)]
value: T, // T must be 16 bits to match the attribute
}
type IntegerAnalog = AnalogInput<Value>;
#[derive(ethercrab_wire::EtherCrabWireRead)]
#[wire(bytes = 2)]
struct Value {
#[wire(bytes = 2)]
raw: u16
};
#[derive(ethercrab_wire::EtherCrabWireRead)]
#[wire(bytes = 4)]
pub struct AnalogInput<T: ethercrab_wire::EtherCrabWireRead> {
#[wire(bits = 1)]
underrange: bool,
#[wire(bits = 1)]
overrange: bool,
#[wire(bits = 2)]
limit1: u8,
#[wire(bits = 2)]
limit2: u8,
#[wire(bits = 1)]
error: bool,
#[wire(pre_skip = 6, bits = 1)]
sync_error: bool,
#[wire(bits = 1)]
tx_pdo_bad: bool,
#[wire(bits = 1)]
tx_pdo_toggle: bool,
#[wire(bits = 16)]
value: T,
}
type IntegerAnalog = AnalogInput<Value>;