Add From and TryFrom implementations for Data #26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?