Feature | Improve array constructors #19
Merged
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.
Context
In order to create a messages backed by a simple array (a pretty common use case) we had dedicated
new_arr
andnew_arr_bytes
constructors which would construct messages backed by[u32; 4]
and[u8; 3]
respectively. This was ok, but if I wanted to create a message backed with a[u32; 2]
I would need to usetry_new
, even though I know at compile time that the buffer would be large enough to fit the message.Additionally, the conversion traits
FromUmp
,IntoUmp
,FromBytes
,IntoBytes
,RebufferFrom
andRebufferInto
would only be available in their fallible versions if the target message was an array because we didn't have compile-time checks on the minimum message size.The Changes
new
All messages, when backed by an array type buffer have a new
new
constructor specialisation. The size of the target array is checked at compile time, so thatnew
will be valid so long as the array has a size larger than the messages minimum representable size.We remove the
new_arr
andnew_arr_bytes
constructors in favour of using the more flexible and more consistentnew
constructor on the explicit array generic specialisation.Conversion Traits
When message is fixed size and the target message is array-backed, and the array has a size greater than the smallest representable size for the message, the conversion traits
FromUmp
,IntoUmp
,FromBytes
,IntoBytes
,RebufferFrom
andRebufferInto
can be used in their non-fallible forms.