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

Tuple support #17

Open
andreiltd opened this issue Oct 5, 2021 · 5 comments
Open

Tuple support #17

andreiltd opened this issue Oct 5, 2021 · 5 comments

Comments

@andreiltd
Copy link

Would you be willing to pull the patch that adds support for tuples? It looks like the code is good to go and it is only a matter of adding impl_trait!((T, T)) for each type and then testing it.

I wouldn't go deep with the size of tuples and only implement pairs which I think is the most common case.

@sdroege
Copy link
Owner

sdroege commented Oct 5, 2021

Unfortunately the memory layout for tuples is not defined. While in practice e.g. a (u8, u8) is the same memory layout as [u8; 2] this is in no way guaranteed (and also the order in which it is stored in memory might be different) and can break in future Rust versions unless it is defined at some point.

@andreiltd
Copy link
Author

andreiltd commented Oct 5, 2021

I see, then there is no way to implement that reliably for now. Thanks for the explanation.

@sdroege
Copy link
Owner

sdroege commented Oct 5, 2021

This could be fixed by submitting a Rust RFC that defines that the memory layout of homogeneous tuples is equivalent to the corresponding array. I don't think there's any practical reason to not define it like that other than nobody having spent time on that yet.

@sdroege sdroege reopened this Oct 5, 2021
@andreiltd
Copy link
Author

rust-lang/unsafe-code-guidelines#36

@sdroege
Copy link
Owner

sdroege commented Oct 19, 2021

The support for primitive arrays from #18 can kind of help here. Instead of working with e.g. (f32, f32) you could work with [f32; 2].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants