Serde: Support derive for types with const generics

Created on 20 May 2018  路  3Comments  路  Source: serde-rs/serde

This has not landed in nightly yet but is being tracked in https://github.com/rust-lang/rust/issues/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],
}
enhancement

Most helpful comment

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.

All 3 comments

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

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!

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pwoolcoc picture pwoolcoc  路  3Comments

dtolnay picture dtolnay  路  3Comments

swfsql picture swfsql  路  3Comments

kleimkuhler picture kleimkuhler  路  3Comments

sackery picture sackery  路  3Comments