Also return remaining bytes in FromBytes conversion methods#1059
Also return remaining bytes in FromBytes conversion methods#1059
FromBytes conversion methods#1059Conversation
|
While I'm obviously in favor of doing this in general, I feel like modifying the existing methods would be too large of a breaking change to be worthwhile, which was why I suggested new methods. |
|
Hm, we'll need to balance the costs of subjecting current users to breaking changes, against the costs of subjecting current and future users to a more bloated API. Adding mut_from
mut_from_prefix
+ mut_from_prefix_split
mut_from_suffix
+ mut_from_suffix_split
mut_slice_from
mut_slice_from_prefix
+ mut_slice_from_prefix_split
mut_slice_from_suffix
+ mut_slice_from_suffix_split
read_from
read_from_prefix
+ read_from_prefix_split
read_from_suffix
+ read_from_suffix_split
ref_from
ref_from_prefix
+ ref_from_prefix_split
ref_from_suffix
+ ref_from_suffix_split
slice_from_prefix
slice_from_suffixThat's quite a hefty addition, and whatever course of action we take here will also likely be taken for our upcoming Since we're preparing for a major breaking release anyways, we have a bit more license than usual to consider breaking changes. |
|
As I discuss in #884 (comment), I'm strongly in support of not removing the plain-casting methods that don't return the suffix. Embedded code should do the minimum work necessary for the job. Zerocopy has a few design decisions that are good for networking code, but bad for embedded, like how all of the I personally find the zerocopy APIs lacking in useful transitive operations like this, so I would prefer the "bloat" of adding these methods and keeping the plain-casting ones. What do you think of these methods starting with I don't care about the mut_from
mut_from_prefix
+ split_mut_from_prefix
mut_from_suffix
mut_slice_from
mut_slice_from_prefix
+ split_mut_slice_from_prefix
mut_slice_from_suffix
read_from
read_from_prefix
+ split_read_from_prefix
read_from_suffix
ref_from
ref_from_prefix
+ split_ref_from_prefix
ref_from_suffix
slice_from_prefix
+ split_slice_from_prefix
slice_from_suffix |
We use it for parsing certain things as well as prefix, and would strongly prefer to have split versions of it as well if you decide to go this route. |
|
I've made a discussion post exploring some of the naming and return type design space: #1095 |
|
I'm inclined to merge this based on the following reasoning:
|
This change makes the slice and non-slice conversion methods consistent, and provides a lightweight way (i.e., without `Ref`) to access the leftover bytes after conversions.
bfa0caf to
e0e9b0d
Compare
This change makes the slice and non-slice conversion methods consistent, and provides a lightweight way (i.e., without
Ref) to access the leftover bytes after conversions. For instance, this:...becomes this, in this PR:
...where the second element of the tuple are the remaining bytes. Providing the remainder eases the pattern where a
Tis parsed from a buffer, and then the buffer is advanced to exclude the parsedT.This PR tests out the 'feel' of tuple-returning conversion methods. Alternatively, we could provide a mirror set of
_splitmethods.Addresses #1051, but is the antithesis of #884. Inspired by #1051 (comment). It's syntactically cheap for users to discard remaining bytes at call sites if they wish, but the alternative — discarding the excess and requiring users to go through
Ref— is syntactically and cognitively expensive.