Skip to content
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

Proposal to add methods to homogeneous tuples ((T, T, ..., T)) so that they can be used as slices (&[T]) #104

Closed

Conversation

nikomatsakis
Copy link
Contributor

Title says it all!

@nikomatsakis
Copy link
Contributor Author

Implemented in rust-lang/rust#14604


# Alternatives

1. Make fixed-length arrays a supertype of homogeneous tuples. More
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the RFC as presented is fine, but this alternative really is more elegant. I'd prefer it if at all possible.

@glaebhoerl
Copy link
Contributor

For what it's worth this would be subsumed by #91 (Coercible). The awkwardness of things like making fixed-length arrays be the supertypes of homogenous tuples, or vice-versa (both directions are valuable), was one of the things which pushed me away from the subtyping model in the first place.

W.r.t. indexing tuples, I've had the idea that their components could be exposed as fields, except numbered rather than named, so: my_tup.2 is the third component of the tuple (if there is one, otherwise compile error), (3, 1, 4, 5, 9).3 == 5, etc. Same for tuple structs. This would close a noticeable features gap relative to structural structs. It could be extended to fixed-length arrays as well.

@bstrie
Copy link
Contributor

bstrie commented Jun 2, 2014

Given that this would only work on homogenous tuples I suppose that this wouldn't preclude the possibility of allowing the compiler to optimize tuple representation?

@bstrie
Copy link
Contributor

bstrie commented Jun 2, 2014

@glaebhoerl, given that these methods would only be implemented on tuples that are congruent to arrays, I think we might as well just reuse the existing array indexing syntax.

@glaebhoerl
Copy link
Contributor

@bstrie The methods @nikomatsakis is proposing would only be for homogenous tuples... but the .0 .1 .2 etc. fields I was floating are for all tuples. (Again, the analogy is struct fields.) Anyway, these ideas are all complementary, I just wanted to mention it because it's related (but otherwise it should have its own RFC).

@eddyb
Copy link
Member

eddyb commented Jun 3, 2014

This is one of the tricks I realized I could have in the library, using VG. I think the old-style RFC has an example of it, actually.
This enables Vec::new(a, b, c, ...) or HashMap::new((k0, v0), (k1, v1), ...), among other useful patterns.

@nikomatsakis
Copy link
Contributor Author

We decided in meeting to take no action here (yet).

withoutboats pushed a commit to withoutboats/rfcs that referenced this pull request Jan 15, 2017
Allows for graceful shutdown of the oneshot by closing and then checking for a
message.

Closes rust-lang#104
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants