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.
I'd like to support const generic arrays, and it didn't seem to hard to implement, so I made a quick PR - of course, I'm not 100% familiar with your design goals, so if this isn't how you'd like things done, let me know and I'd be happy to change it up 😁
This PR adds
JsonSchema
impls for const generic arrays, allowing both arrays with size greater than 32, as well as arrays of any size (for reference, I ran into this while trying to implementJsonSchema
on a type in my crate that wraps a[u8; N]
).There's a couple of downsides:
JsonSchema
.. AFAIK, doing this is impossible in the presence of a const-generic impl without specialization. The compromise was to export a newtype wrapper:EmptyArray<T>
, which provides that impl. Of course, this means that downstream users who relied on[RandomStruct; 0]: JsonSchema
will now need to replace[RandomStruct; 0]
withEmptyArray<RandomStruct>
.I'm not an expert w.r.t. json schema in general, so I guess it seems weird to me to want a schema that says: "this field expects a 0-length array of an unrepresentable type". Is this common in the wild? What's the use-case?
My first thought would actually be to not have the
EmptyArray
type at all, since that seems so "out there", but given that there's already specific tests in place checking that behaviour exists, I thought it best to check before just removing support.Thanks 😁