Is it possible to have something like try_as_mut_bytes(&mut self) for types like enums that only implement TryFromBytes? #2633
Replies: 2 comments 1 reply
-
|
Can you describe a bit about your specific use case? What are you doing with the |
Beta Was this translation helpful? Give feedback.
-
|
Low level message parsing. I had a struct type containing enums with less than 256 variants, and declared an instance of the struct to produce a buffer of the correct size (as if it was a [u8; 123] or whatever size). I wanted to write data into it and then call try_as_ref() or similar to see if the received data parsed correctly. (ie. all the enum fields were valid) It's not hard to work around using size_of::<...>() and a buffer, but it would be nice to just Perhaps what I wanted was not semantically valid now that I think about it. I suppose forcing the use of a u8 buffer rather than MyStruct makes it impossible to accidentally skip the checking step that is performed by try_from_ref. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've got a large number of enums with less than 256 variants where I don't want to implement FromBytes.
They are used in structs that implement TryFromBytes as well.
I recently realized that
as_mut_bytes(&mut self)required FromBytes.Is there a way to get something similar with types that only implement TryFromBytes and not FromBytes?
Beta Was this translation helpful? Give feedback.
All reactions