Would adding this feature cause a breaking change?
No
Is your feature request related to a problem? Please describe.
Some attributes return fixed length byte arrays. (eg a mac address, [u8;6], or the 802.11 VHT MCS Set [u8;32] etc). Some types (eg IP Addresses) have conversions from fixed sized arrays, but not from slices.
Describe the solution you'd like
I would like attr.get_payload_as::<[u8;32]>() to work, which I think is approximately:
impl<const N: usize> FromBytes for [u8;N] { ... }
impl<const N: usize> ToBytes for [u8;N] { ... }
impl<const N: usize> Size for [u8;N] { ... }
(I don't understand the difference between FromBytes and FromBytesWithInput, maybe this should be the WithInput variant? I dunno. This also means I don't understand when to use .get_payload_as() vs .get_payload_as_with_len())
It might also be possible (although I imagine a bit tricker to implement in an efficient manner) to have:
which would allow for arbitrary arrays of u8, u16, u32 and even more complex types. (Interface counters are often returned as arrays of u32 or u64 for instance).
Describe alternatives you've considered
Currently I get the reference to the slice, then use TryFrom to convert it to the correct sized array but this includes an extra error type that couldn't occur if get_payload_as() had returned the correct size.
Would adding this feature cause a breaking change? No
Is your feature request related to a problem? Please describe.
Some attributes return fixed length byte arrays. (eg a mac address, [u8;6], or the 802.11 VHT MCS Set [u8;32] etc). Some types (eg IP Addresses) have conversions from fixed sized arrays, but not from slices.
Describe the solution you'd like
I would like
attr.get_payload_as::<[u8;32]>()
to work, which I think is approximately:(I don't understand the difference between
FromBytes
andFromBytesWithInput
, maybe this should be the WithInput variant? I dunno. This also means I don't understand when to use.get_payload_as()
vs.get_payload_as_with_len()
)It might also be possible (although I imagine a bit tricker to implement in an efficient manner) to have:
which would allow for arbitrary arrays of u8, u16, u32 and even more complex types. (Interface counters are often returned as arrays of u32 or u64 for instance).
Describe alternatives you've considered Currently I get the reference to the slice, then use TryFrom to convert it to the correct sized array but this includes an extra error type that couldn't occur if get_payload_as() had returned the correct size.