Find a way to use Unstrutured *without* unsafe
#2
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.
This is an idea to keep using
Unstructuredin our control plane API without usingunsafeand without lifetime proliferation. Basically, we keep track of which bytes have already been consumed ourselves (with the help ofUnstructured::take_rest) and construct newUnstructuredvalues over the remaining bytes for each call to the control plane API.It involves copying all remaining bytes for each call to the API, so there is a some performance impact. This is because
Unstructuredmay consume bytes from the start of the slice, meaning that we cannot simply truncate our vector to the length of the remaining bytes. But I was able to avoid a heap allocation per API call at least with thetmpbuffer.The API is not generic anymore, because I had issues with the generic lifetime parameter. Maybe it could've been solved, I'm not sure. But I think it wouldn't be too much effort to write one function per data type to be requested if we can still use
arbitraryinternally.A consideration about the desired properties of the control plane:
I think this would be covered by this approach. We can always create a new function that doesn't make use of arbitrary and uses the vector of bytes as a source of decisions directly.