Repository navigation
Add From and TryFrom implementations for Data - #26
Conversation
7a7050d to
d48765a
Compare
|
I think that such auxiliary functions have nothing directly to do with Modbus and should rather be kept separate. |
What do you mean by that? |
|
Sorry, that was my bad, I had forgotten that the fields of |
d48765a to
4c2b1dc
Compare
|
Okay, so I don't have a better suggestion at the moment, and I don't see any other difficulties for now. |
Sometimes a multi byte value is stored over a span of registers, e.g a 64bit value could be stored over 4 consecutive registers. When sending a request to write to such a register, one has to use
WriteMultipleRegisters(Address, Data<'r>), which requires a data.If the rust code is using the value as a 64 bit integer, it is quite cumbersome to convert it to
&[u16]that is required byData::from_words, the only way to construct aData.This PR proposes some
TryFromandFromimplementations to help with these situations. You can now writeSince
Fromcan only be implemented for even number of bytes, a helper macro is used to declare implementations up to[u8; 32](similar howDefaultis implemented for arrays in the standard library).One question: Why is constructing a zero length
Dataforbidden? I don't have a usecase, but should it be allowed?