-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fixed-length arrays implement no traits #7622
Comments
Nominating for feature-complete. |
Just a bug, de-nominating |
The way Haskell has solved this (at least in the case of tuples) is to simply add instances for the first 10 cases. Since, in Haskell, instances need not be in the same module as the class or datatype declaration, a programmer can always add instances for higher numbers if he needs them. Also, for the implementation of higher numbers the programmer could probably just use the implementation of non-fixed sized arrays. |
@yokto we do the same for tuples (mainly via macro generated trait implementions), however the main use case for fixed sized arrays is "large" homogeneous sequences, the ratio between small and large fixed sized vectors will be smaller than small/large tuples so the small implementations won't be as helpful (unfortunately).
Currently This is important for low-level programming (like writing an operating system) where allocations are impossible, and also for performance, since stack allocation is nicer for CPU caches (as well as just avoiding the cost of doing the allocation). |
Fixed in #18486. Closing. |
It doesn't seem like #18486 is relevant to this issue. It's still not possible to implement traits for fixed-size arrays of any size. An especially awful case is the lack of a |
This seems to be fixed: http://is.gd/B7JN4n (rust playpen). |
It looks like it's only fixed for arrays up to size 32: http://is.gd/LHWkJK |
It's still a problem that arrays only implement |
This is particularly problematic with rust-bindgen. rust-bindgen generates things like this:
for unions, and the resulting struct cannot be Copy at all and cannot derive Clone. It looks like this could be very cleanly fixed if rust-lang/rfcs#1038 (types parametrized over numbers) happened. |
Closing; this issue is really subsumed by the desire for const generics, and we've done all we can until those land. (And when they do come, we'll generalize the current trait impls accordingly.) |
Currently fixed-length arrays (i.e.
[f64, .. 3]
) implement no traits, because each size needs to be implemented separately. It'd be nice to be able to parameterise the length.One consequence is that
#[deriving]
doesn't work with them (and gives strange error messages):The text was updated successfully, but these errors were encountered: