-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Reflect for tuples up to length 12 #1218
Conversation
For the second point, unless a use case comes up, I would expect that requiring the lengths to be the same is a sensible restriction. |
Yeah the fact that you can't push to tuples means they aren't a List imo. And given that
Tough call. Reflect::apply is intentionally a bit "fuzzy" to allow "patching" scenarios. So we have to decide if it makes sense to "patch" |
Hmm maybe that isn't true. I would probably impl List for arrays and they can't be pushed to. |
I agree with this. Semantically, tuples are not lists. Tuples aren't designed as collections the same way that lists, sets, and maps are. That being said, tuples have been shown to hold similarities to lists in dynamic languages (for instance Python). I think that if we were to create a new At the very least, if we were to create a I don't mind creating a new |
I noticed there's a |
I think it probably makes sense to use TupleStruct as a base, but I think it should be a new Tuple type (without the name). I'm also totally fine with adding an iterator over tuple values. While that wouldn't normally make sense in a static language, one of the goals of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the changes! I think this is good to go. Just one (very minor) nit.
Add Reflect impls for tuples up to length 12
Implements
Reflect
andList
for tuples with 0-12 elements (#1022). Since traits in the standard library are only implemented for tuples up to length 12, I figured that the same restriction could apply here.Open questions:
List
?serde_json
serializes tuples as arrays, so it might make sense to follow that precedent. The downside is thatList::push
can't be implemented for tuples, so it must panic.Reflect::apply
ensure that the other value has the same length as the tuple, or is it safe to allow values with fewer elements for a partial apply? Currently, it will only panic if the incoming value has more elements than the tuple supports.