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

Support derive for types with const generics #1272

Closed
dtolnay opened this issue May 20, 2018 · 5 comments
Closed

Support derive for types with const generics #1272

dtolnay opened this issue May 20, 2018 · 5 comments

Comments

@dtolnay
Copy link
Member

dtolnay commented May 20, 2018

This has not landed in nightly yet but is being tracked in rust-lang/rust#44580.

It would be good to begin thinking about how to form the right trait bounds for such types.

#[macro_use]
extern crate serde_derive;

#[derive(Serialize, Deserialize)]
struct S<T, const N: usize> {
    array: [T; N],
}
@dtolnay
Copy link
Member Author

dtolnay commented Feb 1, 2019

Will reopen if the implementation in the compiler ever lands and we start hearing use cases.

@dtolnay dtolnay closed this as completed Feb 1, 2019
@JulianKnodt
Copy link

JulianKnodt commented Jun 21, 2020

Hi, I hope it's ok that I'm commenting on an older thread, but I was wondering if this was being revisited now that const-generics are available on nightly?

The main use case for const-generics would probably be in numerical applications, so I can see the main use case serving a similar role to numpy's .npy or .npz format.

If there is anything I can do to implement this let me know!

JulianKnodt added a commit to JulianKnodt/quick_maths that referenced this issue Jun 21, 2020
Unfortunately serde does not seem to support const-generics yet. I put in an issue at
serde-rs/serde#1272 for this, so we'll see where that goes.
JulianKnodt added a commit to JulianKnodt/quick_maths that referenced this issue Jun 21, 2020
Unfortunately serde does not seem to support const-generics yet. I put in an issue at
serde-rs/serde#1272 for this, so we'll see.
@vadixidav
Copy link

I second this as I would like to switch the hnsw crate to const generics in preparation for its stabilization. Having a feature that enabled those impls would be beneficial. Alternatively, serde could automatically detect if it is on a compatible nightly rust version using select-rustc and enable the const generics impls in that case.

@Kromey
Copy link

Kromey commented May 5, 2021

Const generics have landed in stable now, and as I noted in the above linked issue I cannot currently derive Serde traits because I use this feature. While I can probably work around it via the try_from and into attributes, having the ability to derive them instead would greatly simplify the task.

@TehPers
Copy link

TehPers commented May 6, 2021

I believe this issue was reopened in #1937. I'm also looking forward to this being implemented in the future.

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

No branches or pull requests

5 participants