Allow ValueSet
s to be constructed with slices in addition to arrays
#2787
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.
Motivation
I'm working on an implementation of
Subscriber
that needs to be able to store (in a form as close as possible to the original) the inputs to its methods, and reconstruct them later to be passed to anotherSubscriber
. For the most part, this works really well, but the biggest sticking point by far came from trying to reconstruct aValueSet
from a stored list of(Field, Value)
pairs.The core of the problem is the
ValidLen
trait and its usage byFieldSet::value_set()
. In order to call that function, you have to be able to provide a statically-sized array, because that's the only type that implementsValidLen
.While, in theory, constructing an array for my use case should be just about possible (although the tricks necessary to do so likely involve a macro and the reimposition of an arbitrary length limit), lifetime issues (that appear to result from a call to
<[_; N]>::try_from()
) make it impossible. I'm going to construct a minimal example of this and investigate further at some point, but in the meantime:Solution
Since #2508 removed the limitation on array length here, there doesn't seem to be a drawback to simply adding an implementation of
ValidLen
for slices. They already meet theBorrow
supertrait requirement, so no additional machinery is needed.This makes this API trivially easy to call for my use case, and I can't think of any associated drawbacks.