Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upImplement From<[T; ..]> for (T, ..) and From<(T, ..)> for [T; ..] #30736
Conversation
rust-highfive
assigned
alexcrichton
Jan 6, 2016
This comment has been minimized.
This comment has been minimized.
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
This comment has been minimized.
This comment has been minimized.
|
I think it makes sense to only implement this for tuples up to size 12 in both directions in order to keep it symmetrical. |
This comment has been minimized.
This comment has been minimized.
|
I also noticed that the order of the elements may be wrong. Could I get some additional feedback on the nature of the changes? And if it's approved, I'll clean up the PR. |
This comment has been minimized.
This comment has been minimized.
|
I think something like this would be very useful. Shame about that Clone requirement though. |
This comment has been minimized.
This comment has been minimized.
|
It's possible to implement this without the EDIT: Another option is slice patterns (though they are unstable): let [a, b, c] = [1, 2, 3];
(a, b, c) |
This comment has been minimized.
This comment has been minimized.
Doesn't work either: http://is.gd/Kmwznm But yeah I could use |
This comment has been minimized.
This comment has been minimized.
|
Then go the |
This comment has been minimized.
This comment has been minimized.
|
@tomaka This seems to work: fn foo<T>([a, b, c]: [T; 3]) -> (T, T, T) {
(a, b, c)
} |
This comment has been minimized.
This comment has been minimized.
|
rustc has something related that I'd love to have. Could be |
tomaka
force-pushed the
tomaka:tuple-arrays-conv
branch
from
4c56f67
to
9940953
Jan 6, 2016
This comment has been minimized.
This comment has been minimized.
|
@bluss That's really nice, but I guess that the problem is that the internal representation of tuples may change in the future. Anyway, this PR should now be good to go except for the issue number. |
This comment has been minimized.
This comment has been minimized.
|
I still don't think tuple->array conversions should be implemented to tuples longer than 12 as nothing else is implemented for tuples that long. |
This comment has been minimized.
This comment has been minimized.
|
@tomaka Right. Given the rustc trait, I was hoping we could solidify the repr. |
huonw
added
I-nominated
T-libs
labels
Jan 7, 2016
This comment has been minimized.
This comment has been minimized.
|
Stability doesn't work for trait implementations, so these will be automatically stable if they land. (Nominating for libs team discussion.) |
alexcrichton
reviewed
Jan 11, 2016
| #[stable(since = "1.4.0", feature = "array_default")] | ||
| impl<T> Default for [T; $n] where T: Default { | ||
| fn default() -> [T; $n] { | ||
| [$t::default(), $($ts::default()),*] | ||
| } | ||
| } | ||
| array_impl_default!{($n - 1), $($ts)*} | ||
|
|
||
| #[unstable(feature = "array_from_tuple", reason = "recently added", issue = "0")] |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jan 11, 2016
Member
These'll be insta-stable unfortunately so could these be #[stable] instead of #[unstable]?
This comment has been minimized.
This comment has been minimized.
|
I agree with @huonw that we'll likely want to chat about this in the libs triage. I'm personally a little wary about adding these sorts of impls as it seems there is no end to the various sorts of conversions that could be added. |
This comment has been minimized.
This comment has been minimized.
|
The motivation behind this change is that there is no consensus on whether a geometrical vector or geometrical point should be represented as |
This comment has been minimized.
This comment has been minimized.
|
The libs team discussed this in triage yesterday and the conclusion was to close this for now. While we typically have these sorts of conversions for arrays it's normally done with the intention of replacing it with type-level generic integers one day. A feature such as this, however, would require a relationship between variadic generics, tuples, and type-level integers which is likely much farther out. As a result we concluded that it should be fine to have small conversion functions in-crate for these now. |
tomaka commentedJan 6, 2016
This adds:
And same for all other arrays and tuples dimensions, up to 32 elements for tuple->array and up to 12 elements for array->tuple (similar to the other trait implementations on arrays and tuples).
Note that the first one requiresFixed.Clone, because otherwise I couldn't manage to make it compile.If the changes are good, this still needs
some tests andan issue number.